Reputation: 3
I have a htaccess question that I think may be so simple (dumb?) that no one has had to ask it before. I converted from using html pages to php and for the most part the following has worked:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.+)\.htm$ /htmlrewrite.php?page=$1 [R=301,NC,L]
</IfModule>
There are a couple of exceptions though so I assumed putting:
Redirect 301 /oldpage.htm http://example.com/newpage.php
above the IfMofule... would do the trick but it doesn't. The "Redirect 301" is being ignored unless I remove the rest of the code. Could someone tell me what I'm doing wrong?
TIA.
Upvotes: 0
Views: 1402
Reputation: 143906
You're using mod_rewrite and mod_alias together and they are both getting applied to the same URL. You should stick with either mod_rewrite or mod_alias.
mod_rewrite: (remove the Redirect
directive)
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^oldpage.htm$ http://example.com/newpage.php [R=301,L]
RewriteRule ^(.+)\.htm$ /htmlrewrite.php?page=$1 [R=301,NC,L]
</IfModule>
mod_alias: (remove everything in the <IfModule mod_rewrite.c>
block:
Options +FollowSymlinks
Redirect 301 /oldpage.htm http://example.com/newpage.php
RedirectMatch 301 ^/(.+)\.htm$ /htmlrewrite.php?page=$1
Upvotes: 1
Reputation: 1364
Apache processes mod_rewrite (Rewrite*) first and then mod_alias (Redirect).
Use RewriteCond
to prevent /oldpage.htm from processed by mod_rewrite.
RewriteCond %{REQUEST_URI} !^/oldpage\.htm$
RewriteRule ^(.+).htm$ /htmlrewrite.php?page=$1 [R=301,NC,L]
Or use RewriteRule
instead of Redirect
.
RewriteRule ^oldpage\.htm$ http://example.com/newpage.php [L,R=301]
RewriteRule ^(.+).htm$ /htmlrewrite.php?page=$1 [R=301,NC,L]
Upvotes: 0