I tried the following code in .htaccess to 301 redirect www.example.com/?content=file.php&id=16 www.example.com/file/This-is-the-title/16
RewriteEngine on
Redirect 301 /?content=file.php&id=16 /file/This-is-the-title/16
But it's not redirecting. The URL remains as it is.
What am I doing wrong?
P.S. I'm not asking for rewrite or so. I need a 301 redirect.
The Redirect directive doesn't match query strings. Use this instead:
RewriteEngine on
RewriteCond %{QUERY_STRING} =content=file.php&id=16
RewriteRule ^$ /file/This-is-the-title/16? [R=301,L]
Related
I would like to make some massive redirects in .htaccess because of a migration. I'm using both RewriteRule and Redirect 301. But the RewriteRule keeps overwriting the Redirect 301 rules, despite of the order.
For example:
I would like to redirect /retraites-nl-cat-595.html to https://www.vihara.nl/meditatieretraites/
But all the other url's that contains 595 to https://www.vihara.nl/tag/vipassana/
I have this in .htaccess:
RewriteEngine on
RewriteRule ^$ https://www.vihara.nl [R=301]
Redirect 301 /retraites-nl-cat-595.html https://www.vihara.nl/meditatieretraites/
RewriteRule ^(.*)595(.*)$ https://www.vihara.nl/tag/vipassana/ [L,R=301]
But this is not working because the RewriteRule is overruling the Redirect 301 rule. The same happens when I switch the order of the last 2 lines.
Is there a way to change this? So the Redirect 301 will be overruling the Rewrite rule, instead of the other way around?
First I need to redirect these pages to another page in a different domain
Redirect 301 /example1 http://newdomain.com/test1
Redirect 301 /example2 http://newdomain.com/random1
Note the pages are not the same in the new domain (e.g., /example1 to /test1)
After that, I need redirect the rest of the pages to newdomain.com
E.g., Redirect 301 (everything else) to http://newdomain.com
Try below rule, using mod rewrite I am assuming you have mod rewrite enabled.
RewriteEngine On
RewriteRule ^example1$ http://newdomain.com/test1 [R=301,L]
RewriteRule ^example2$ http://newdomain.com/random1 [R=301,L]
RewriteCond %{REQUEST_URI} !^(example1|example2)
RewriteRule ^ http://newdomain.com [R=301,L]
If you want to use mod-alias , you can use these redirects :
RedirectMatch 301 ^/example1/?$ http://example.com/test1
RedirectMatch 301 ^/example2/?$ http://example.com/random1
#redirect everything else to the homepage of example.com
RedirectMatch ^.+$ http://example.com/
Clear your browser cache before testing these redirects.
Try this in your .htaccess
RewriteEngine On
RewriteRule ^(.*)$ http://newdomain.com/ [R=301]
I have an htaccess file with over 700 redirects and most of them are not working at all. I get a 404 page mostly even though they are on the same domain. Here's 5 of them that aren't working:
Redirect 301 /orlando-airport/fly-snooze-cruise-hotel-packages-orlando-airport-1-person.html /fly-snooze-cruise/orlando-airport/
Redirect 301 /orlando-airport/fly-snooze-cruise-hotel-packages-orlando-airport-2-people.html /fly-snooze-cruise/orlando-airport/
Redirect 301 /orlando-airport/fly-snooze-cruise-hotel-packages-orlando-airport-3-people.html /fly-snooze-cruise/orlando-airport/
Redirect 301 /orlando-airport/fly-snooze-cruise-hotel-packages-orlando-airport-4-people.html /fly-snooze-cruise/orlando-airport/
Redirect 301 /orlando-airport/fly-snooze-cruise-hotel-packages-orlando-airport-5-people.html /fly-snooze-cruise/orlando-airport/
I have checked the domains Please tell me what I am doing wrong. All help is appreciated.
You can use only one:
RewriteRule ^orlando-airport/fly-snooze-cruise-hotel-packages-orlando-airport-\d+-person\.html$ /fly-snooze-cruise/orlando-airport [R=301,L]
OK, I found out that the rewrite rules in the mod_rewrite section somehow messed with the redirects. So I converted the "Redirect 301"s to Rewrite Rules in mod_rewrite.c and everything is working.
RewriteRule ^orlando-airport/fly-snooze-cruise-hotel-packages-orlando-airport-1-person.html$ /fly-snooze-cruise/orlando-airport [R=301,L]
RewriteRule ^orlando-airport/fly-snooze-cruise-hotel-packages-orlando-airport-2-people.html$ /fly-snooze-cruise/orlando-airport [R=301,L]
RewriteRule ^orlando-airport/fly-snooze-cruise-hotel-packages-orlando-airport-3-people.html$ /fly-snooze-cruise/orlando-airport [R=301,L]
RewriteRule ^orlando-airport/fly-snooze-cruise-hotel-packages-orlando-airport-4-people.html$ /fly-snooze-cruise/orlando-airport [R=301,L]
RewriteRule ^orlando-airport/fly-snooze-cruise-hotel-packages-orlando-airport-5-people.html$ /fly-snooze-cruise/orlando-airport [R=301,L]
I'm using something similar to the following:
RewriteEngine on
Redirect 301 / http://newdomain.co.uk/link/
Redirect 301 /showcase.asp?showcaseid=1 http://newdomain.co.uk/track1
Redirect 301 /showcase.asp?showcaseid=2 http://newdomain.co.uk/track2
Redirect 301 /showcase.asp?showcaseid=3 http://newdomain.co.uk/track3
Redirect 301 /showcase http://newdomain.co.uk/link/tracks
With that in mind any URL other than the mentione would go to http://newdomain.co.uk/link
Which is fine however any of the other URL's that use a "?" go to say http://newdomain.co.uk/link/showcaseid=1 for /showcase.asp?showcaseid=1
Also with the
Redirect 301 /showcase http://newdomain.co.uk/link/tracks
can I just write as follows:
Redirect 301 /showcase tracks
You can't match against the query string (everything after the ?) in a Redirect directive. You have to use mod_rewrite's %{QUERY_STRING} variable:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^showcaseid=([0-9])
RewriteRule ^showcase\.asp$ http://newdomain.co.uk/track%1 [L,R=301]
RewriteRule ^showcase$ http://newdomain.co.uk/link/tracks [L,R=301]
RewriteRUle ^$ http://newdomain.co.uk/link/ [L,R=301]
Note that the order is important. You generally want the more general matching rules to be at the end.
I am trying to redirect from the following URL concepts into a 301 redirect URL but keep failing (doesnt seem to be working).
/blahblah?area=something
to
www.newdomain.com/blahblah/
I have tried the following but it did not working
Redirect 301 /blahblah.php/\?area=something www.newdomain.com/blahblah/
You can use this rule in your root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} /blahblah\.php/\?area=something [NC]
RewriteRule ^ /blahblah/$ [R=302,L]