Redirects in htaccess file not working - .htaccess

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]

Related

How to stop RewriteRule overruling Redirect 301 in htaccess

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?

htaccess 301 redirect rules issue

I am trying to do a simple redirection, but I encounter this error, when I do the 301 redirect using the htaccess, it returns the redirect but with the value
.htaccess
RewriteRule ^clientes/(\w+)/?$ clientes.php?id=$1 [L]
Redirect 301 /clientes/juan http://google.es
result:
https://www.google.es/?id=juan&gws_rd=ssl
It's because you are mixing mod-alias (Redirect) with mod-rewrite (RewriteRule) . These are two diffrent modules with diffrent runtime behaviour .
Try using this :
RewriteRule ^clientes/juan http://google.com [L,R=301]
RewriteRule ^clientes/(\w+)/?$ clientes.php?id=$1 [L]
Clear your browser cache before testing these rules.
this working, but my problem is with this line.
Rewriterule ^videos/(.*)_(.*).html$ index.php?tag=$1&page=$2 [L,NC]
Rewriterule ^videos/(.*).html$ index.php?tag=$1 [L,NC]
RewriteRule ^/videos/juan.html https://www.dominio .com/cat/conduccion-juan/ [R=301,L]
and this not working
redirect 301 /videos/juan.html https://www.dominio.com/videos/conduccion-juan.html
thank you!

Redirect 301 specific pages and the rest to just one page

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]

.htaccess; 301 redirect not working

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]

301 Redirect Conflict with www redirect

I am having an issue with my 301 redirects.
I just upgraded my site from an html based site to a joomla site. SO I am trying to redirect the 50 or so pages to the new joomla based navigation.
SO what is working:
rewrite rule to remove index.php, and the www., and 301 redirects
What isn't working:
301 redirect with a www in front of it.
www.sample.com/page.html
It sends them to the home page instead of the page, it takes them to the home page.
Here is my www rewrite rule.
## Redirects to www.
RewriteEngine On
RewriteCond %{HTTP_HOST} www.sample.com
RewriteRule (.*) http://sample.com/$1 [R=301,L]
Here is my 301 rule
Redirect 301 /page.html /page
Thanks for the help.
If you are trying to remove the www then you might want to change the matching up some. Try your rule like this.
## Redirects to www.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.sample\.com$ [NC]
RewriteRule (.*) http://sample.com/$1 [R=301,L]
RewriteRule ^page.html$ /page [R=301,L]
RewriteRule ^page2.html$ /page2 [R=301,L]

Resources