问题
I have asked a question here yesterday and user "faa" tried to help me, but unfortunately we couldn't solve the issue.
Original question is here: Rewriting url with htaccess when a directory exists
I am doing a simple rewrite but it is not working (apparently) due to directory access permissions.
The Code:
*Dynamic Page: url.com/index.php?page=download
Rewrite Rule: ^download$ /index.php?page=download
The problem:
A directory named "download" exists. When the rewrite rule tries rewrite the Dynamic Page* to the path "download", it returns a 403 FORBBIDEN error and the page gets rewritten to "download/?page=download".
Now, if I rename that directory to something else, like "downloads", then it works.
-- EDIT --
My server, by default, protects every directory with a "403 Forbbiden Error". I believe this is the reason why it's not working, but I'm not sure. Is it a conflict indeed? What is happening?
回答1:
/download/?page=download
The reason why this is happening is because somewhere mod_dir redirects all requests for directories that are missing the trailing slash to include the trailing slash. This is interferring with your rewrite rule. Since your server is automatically setup to deny listing of directories, it's probably safe to go ahead and turn directory slashes off:
DirectorySlash Off
回答2:
Try
RewriteRule ^download[/]?$ index.php?page=download
The rule matches even if the path was supplied with a /, so the directory download can't be accessed.
Make sure the RewriteRule executes even after a redirect.
来源:https://stackoverflow.com/questions/16346691/rewrite-rule-leads-to-403-forbbiden-error