i add this rules to my .htaccess file:
RedirectMatch 301 /wp-content/my-image-5x5.jpg /wp-content/default-5x5.jpg
Redirect works well, but add the old image name into address.
Why? I don't need this.
What i'm get now:
www.mypage.lt/wp-content/default-5x5.jpg?file=/wp-content/my-image-5x5.jpg
What i need:
www.mypage.lt/wp-content/default-5x5.jpg
Redirect works well, but add the old image name into address. Why? I don't need this.
This is because you have wordpress rules which does internal routing (to an index.php file) and the rewrite rules belong to mod_rewrite, while the RedirectMatch directive belongs to mod_alias. These modules both get applied at different points in the URL-file mapping pipeline, thus both get applied, and you end up with a mangled redirect URL. You should stick to only mod_rewrite in this instance. Try adding these rules before your wordpress rules:
RewriteEngine On
RewriteRule ^/?wp-content/my-image-5x5.jpg /wp-content/default-5x5.jpg [L,R=301]
Related
i have a couple of unwanted urls that i want to redirect:
/faq/
/faq/question/1-title
/faq/question/2-title
I want all the /faq/question/* urls to redirect to /faq, is that possible?
I have this but this doesnt work :
RedirectMatch 301 ^/faq/question/([^/]+)/?$ /faq
With your shown samples/attempts, please try following htaccess rules file. Make sure you are putting this new rule at top of your htaccess file(after https rules(to change http --> https rules) in case there are any present in your htaccess file).
Also make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
##Put your new rule here..
RewriteRule ^faq/question/ /faq? [R=301,L,NC]
###Make sure to keep rest of your urls here onwards...
Switching from ExpressionEngine to Wordpress and need to set up redirects in htaccess.
The paths to the articles will change from mysite.com/section/read/article-name
to mysite.com/article-name/. The section part of the path has six variants.
Unsure whether to look at redirectmatch or rewrite rule being a toatl novice with htaccess.
Thanks
Either would work, so I'll use RedirectMatch. To be specific about the section name, it would be:
RedirectMatch 301 "/(?:section|another-section|third-section)/read/(.+)$" /$1
Replacing your section names in there, separated by pipes.
Or for anything in a directory called read in a top level directory:
RedirectMatch 301 "/[^/]+/read/(.+)$" /$1
Since it is a one to one mapping and just the final part to be preserved, you don't need RedirectMatch. Redirect is sufficient
Redirect /section/read /
When it works as expected, you may set the status code to 301.
Redirect 301 /section/read /
If you want to use mod_rewrite instead, this would be
RewriteRule ^section/read/(.*)$ /$1 [R,L]
When everything works as it should, you may replace R with R=301. Never test with R=301.
So i have this issue, with changing an old site with a new and I need to redirect all the old links. So have this:
domain.com/articles.php?var=1
I basicly want to redirect everything after articles.php to just domain.com, including the /articles.php.
Thank you in advance.
Try adding this to your htaccess file:
RedirectMatch 301 ^/articles\.php$ /
or if you have mod_rewrite rules already in your htaccess file, you need to use mod_rewrite isntead, and add this rule above whatever rules are already there:
RewriteRule ^articles\.php$ / [L,R=301]
I bought an old site that apparently used some kind of a CMS, maybe wordpress.
Now it's a simple html site. I want to redirect www.example.com/main and everything in that directory to root. In other words, if a url is example.com/main/a_bunch_of_garbage that should 301 redirect to the homepage. Here is what I have but it doesn't quite work.
Options +FollowSymLinks
RewriteEngine on
RedirectMatch 301 ^/main/(.*)$ http://www.example.com
If the url doesn't contain any weird characters like ? or = then it works. But for example, if I go to www.example.com/main/index.php?option=com_content&view=post&id=84&Itemid=982/
Then although it does redirect to the homepage, in the address bar, I still see the entire URL. Can I fix this?
I also just remembered another problem I had. If I put example.com/main (without forward slash after main) the redirect doesn't work. It only works if I put example.com/main/ (with forward slash)
You need to use mod_rewrite rules only and avoid mixing RedirectMatch here. Have your rules like this in your root .htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^main(/.*)$ $1? [L,NC,R=301]
? in the end is used to strip off any existing query string.
I'm trying to accomplish such RewriteCond but I'm having problem with regex
REDIRECT to domain1.tld ONLY IF current address is domain2.tld/test/ but NOT IF domain2.com/test/_appz/
domain can be irrelevant:
REDIRECT to domain1.tld ONLY IF current address consists of directory /test/ but NOT IF in /test/_appz/ and deeper
I want to achieve conditions:
domain2.tld/test/ >>> redirect
domain2.tld/test/_appz/ >>> stay
otherdomain.tld >>> stay
EDIT:
I'm writing own CMS for very own purposes, got 2 domains pointing to the same public_html,
one is official and one is used only to access via CMS.
cms.domain2.tld/test/ >>> redirect to domain1.com
cms.domain2.tld/test/_appz/ >>> no redirect
domain1.tld>>> no redirect (as it will be loop)
domain1.tld and cms.domain2.tld pointing to the same dir where that .htaccess exist
Thanks 4 your help in advance!
You can use either mod_alias or mod_rewrite to do redirection. Note that using mod_alias, you don't want to use the Redirect directive, which will virtually link two path nodes, this isn't what you want.
mod_alias
In the htaccess file in domain2.tld's document root, add:
RedirectMatch ^/test/?$ http://domain1.tld/
If you want a permanent redirect:
RedirectMatch 301 ^/test/?$ http://domain1.tld/
mod_rewrite
If you have rewrite rules that may interfere with mod_alias, then you may want to stick with just mod_rewrite. Also, if both the domain1.tld and domain2.tld share the same document root, you won't be able to use mod_alias. You'd want something like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} domain2.tld$ [NC]
RewriteRule ^/?test/?$ http://domain1.tld/ [L,R]
If you want a permanent redirect, change the flags to [L,R=301].