Reputation: 141
On my, I want to redirect everything that comes after www.mysite.nl/news/ back to www.mysite.nl/news, except for www.mysite.nl/news/page (and everything that comes after /page)
How do I do such thing with .htaccess?
EDIT: I'm using these rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^news/page.*$ index.php [L]
RewriteRule ^news/.+ news/ [R=301,L]
</IfModule>
Upvotes: 0
Views: 81
Reputation: 1753
First run a rewrite rule for the subfolder you wish to exclude - /news/page - first.
Use -
to mean "don't redirect" and [L]
for "Last thing, stop now if you match".
Or, if you want it to run through WordPress, use index.php
Then redirect URLs that start /news/
This way, the excluded subfolder will not reach the redirect rule.
So:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^news/page.*$ index.php [L]
RewriteRule ^news/.+ news/ [R=301,L]
</IfModule>
Use .+
to mean one or more any-character instead of .*
which means any or none any-character, to avoid redirecting news/ to news/.
Upvotes: 1
Reputation: 12469
This should work for you:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/news/page.* [OR]
RewriteCond %{REQUEST_URI} !^/news
RewriteRule / http://mysite.nl/news [R=301,L]
This will redirect everything but the /news
or news/page
to the /news
folder.
Upvotes: 0