I’m having issues with files in my root folder as well as files with the same name in the sub-folders being redirected. Here’s my htaccess file:
rewriteengine on
rewritecond %{http_host} ^mydomain.com [nc]
rewriterule ^(.*)$ http://www.mydomain.com/$1 [r=301,nc]
redirect 301 /newsletters/ http://www.mydomain.com
redirect 301 /sample.html http://www.mydomain.com
The folder redirect works fine, but sample.html will redirect (great!) but so will /folder/sample.html /randomfolder/folder/sample.html and so on (not so great).
Any ideas? I’ve tried just using sample.html without the slash prefix but it simply doesn’t redirect at that point.
Thanks!
Use a
RewriteRuledirective with a regular expression. Start with a^to only match the start of the string.