Reputation: 6159
So I have this website: www.example.com, which in the past would redirect the clients to www.example.com/subdir
Now I updated the whole site, and the subdirectory doesn't exist anymore, and I want the main domain to be the root. The problem is that many clients have cached the url with the subdomain included, so I need a redirection rule to route www.example.com/subdir to www.example.com.
I tried this:
RewriteRule ^subdir/(.*)$ $1
which works if I enter www.example.com/subdir/ with the last slash
but if I access www.example.com/subdir without last slash it won't do the job.
How can I make it work?
Upvotes: 2
Views: 95
Reputation: 784908
Change your rule to this:
RewriteRule ^subdir(?:/(.*))?$ /$1 [L,NC,R=301,NE]
It is important to use R=301
here so that all clients and search engines eventually move to new URL rather than keep using duplicate URL for the same content (bad SEO).
Upvotes: 3