Redirect directory to file using htaccess?
I'm trying to do something like this...
Redirect mysite.com/directory/ To mysite.com/directory/do
But ONLY when "/directory/" is 开发者_JAVA技巧opened without pointing to a file. I am aware that "DirectoryIndex" can help with this, but I want the file's name (which is "do") to appear in the url the users sees. Is there a way to accomplish this with .htaccess..?
Thanks in advance!
If I've understood correctly, you want something like this:
RewriteEngine On
# Only redirect if we're in /directory/ and *not* pointing at
# a file that already exists in the filesystem
RewriteCond %{REQUEST_URI} ^/directory/
RewriteCond %{REQUEST_URI} !-f
RewriteRule . /directory/do [R,L]
Alternatively, if you meant "when the user accesses the URL mysite.com/directory/ fullstop", which on second thought you may have, this will work as well:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/directory/$
RewriteRule . /directory/do [R,L]
Edit: In case /do isn't an actual file:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/directory/
RewriteCond %{REQUEST_URI} !^/directory/do$
RewriteCond %{REQUEST_URI} !-f
RewriteRule . /directory/do [R,L]
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/redeem/surveys/$ [NC]
RewriteCond %{REQUEST_URI} !-f
RewriteRule ^(.*)$ /redeem/surveys/do$1 [L,R=301]
That works...but can it be better...?
精彩评论