Welcome to WebmasterWorld Guest from 54.198.164.83

Forum Moderators: Ocean10000 & incrediBILL & phranque

nginx htaccess redirects

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

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

Full Member

10+ Year Member

joined:Oct 6, 2003
posts:235
votes: 0

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.
7:47 pm on Oct 26, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:14608
votes: 598


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.
8:47 pm on Oct 26, 2017 (gmt 0)

Senior Member

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

joined:Sept 25, 2005
posts:1753
votes: 254


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