.htaccess Redirect Any Subfolder Access
Lots of different answers but none that fit my scenario after 15 pages of Google results. I've tried using -Index and RedirectMatch, but they prevent files from being accessed.
I need any attempts to access any folders (or incorrect URLs) in mysite.com/media/ to be redirected to mysite.com
However, the content should still be accessible to the website itself (i.e. scripts, CMS, etc.)
e.g. mysite.com/media/, mysite.com/media/sub1/, mysite.om/sub1/sub2/, mysite.com/media/doesntexist.html, etc. all redirect to mysite.com/
Basically, no acc开发者_StackOverflow社区ess to /media/ or its contents unless you know the exact URL.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/media http://example.com/ [R=301,L]
# not sure if the '/' after '^' should be there, so remove if not working
if the requested file from the media folder doesnt't exist, than redirect to example.com
Create a .htaccess file in web root
Options -Indexes +FollowSymLinks
RewriteEngine on
RewriteRule /media http://www.yoursite.com/ [R=301,L]
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
精彩评论