Answer the question
In order to leave comments, you need to log in
Why don't mod_rewrite examples work?
I want to know all the subtleties of mod_rewrite, so as not to blindly copy htaccess. To do this, I opened httpd.apache.org/docs/current/rewrite/intro.html and there is an example: If DocumentRoot is set to /usr/local/apache2/htdocs, then this directive would map requests for example.com/foo to the path /usr/local/apache2/htdocs/bar.
To make it work properly, I created a bar folder at the root of the site and placed the index.php file there, hoping that it would open when I went to example.com/foo. But no. Not Found
The requested URL /foo/ was not found on this server.
Why?
RewriteEngine On is enabled and
DirectoryIndex index.php works too.
Simple redirects work "RewriteRule .*
RewriteRule "^/foo$" "/bar"
example.com "
Answer the question
In order to leave comments, you need to log in
After some magic with regular expressions, I realized that the slash before foo is superfluous.
Correctly so:
Conclusion: on httpd.apache.org/docs/current/rewrite/intro.html examples with errors.
RewriteRule "^/foo$" "/bar"
/
/
In VirtualHost context, The Pattern will initially be matched against the part of the URL after the hostname and port, and before the query string (eg "/app1/index.html"). This is the (%-decoded) URL path.
In per-directory context (Directory and .htaccess), the Pattern is matched against only a partial path, for example a request of "/app1/index.html" may result in comparison against "app1/index.html" or "index .html" depending on where the RewriteRule is defined.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question