Forum Moderators: phranque

Message Too Old, No Replies

nginx htaccess redirects

looking of a way to make a rewrite rule not ignore 301 redirects in htacess

         

stinkfoot

2:43 pm on Oct 26, 2017 (gmt 0)

10+ Year Member


Hi,

I have 1000's of individual pages that are now 301 redirects in my htaccess on an nginx server.

eg Redirect 301 /directoryname/pagename.html https://www dot anewdomain dot com/newpage

All of them work fine. After 1000's of these I want to make sure any other requests to that directory are also redirected and dont end up as 401 page not found.

I have tried the below method but it does not work.

Redirect 301 /directoryname/pagename.html https://www dot anewdomain dot com/newpage
Redirect 301 /directoryname/pagename1.html https://www dot anewdomain dot com/newpage1
RewriteRule ^directoryname/(.*?)$ https://www dot anewdomain dot com [R=301,NE,NC,L]

What happens is all of the Redirect 301's get ignored and the Rewrite rule takes precedence? All requests to any page in /directoryname/ that were previously redirected by Redirect 301 /directoryname/pagename.html https://www dot anewdomain dot com/newpage are ignored. All requests now redirect the same as this rule RewriteRule ^directoryname/(.*?)$ https://www dot anewdomain dot com [R=301,NE,NC,L]

How can I get it so that ONLY requests for pages in that directory without Redirect 301 /directoryname/pagename.html https://www dot anewdomain dot com/newpage are redirected to https://www dot anewdomain dot com?

Thanks in anticipation of your help.

lucy24

7:47 pm on Oct 26, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Short answer: do not mix mod_alias (Redirect by that name) and mod_rewrite (RewriteRule) in the same access. First convert all your existing rules to mod_rewrite syntax and put them in most-specific-to-least-specific order.

Then come back with any remaining problems.

robzilla

8:47 pm on Oct 26, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm confused. How are you using .htaccess with an nginx server? Is it a proxy server in front of Apache?