I Cannot get rewriterule to work
-
13-11-2019 - |
Question
I'm using VertrigoServ 2.27 on my laptop (localhost:8080).
Rewrite module is enabled and i tested it with alice.html and bob.html example (http://stackoverflow.com/questions/6944521/url-rewriting-on-localhost) and it works with .htacces inside www-subfolder. And I also put rubbish text inside .htaccess and I got error from Apcheserver so rewrite mod is running and I cab use rules.
here is the rule: (inside /www/folder1/.htaccess) Options +FollowSymLinks RewriteEngine On RewriteRule /(.*) /index.php?disp=$1 [QSA,L]
So when I put this url into browser my index page loaded ok. http://localhost:8080/folder1/index.php
And the problem is here: When I request login via index.page(login page) and send url to localhost server by cliking send-button the url changed localhost:8080/login, it should be localhost:8080/folder1/login
- how I can keep subfolder name in url?
and I want convert urls like this: www.best-food-of-the-usa.com/index.php?operation=top&state=arizona& city=mesa&limit=10
to like this: www.best-food-of-the-usa.com/arizona/mesa/top10.html
Any help is appreciated. Thanks \Jose
Solution
RewriteRule
is behaving as the docs say.
From RewriteRule Directive Apache Docs
What is matched?
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 (e.g. "/app1/index.html").
In Directory and htaccess context, the Pattern will initially be matched against the filesystem path, after removing the prefix that lead the server to the current RewriteRule (e.g. "app1/index.html" or "index.html" depending on where the directives are defined).
If you wish to match against the hostname, port, or query string, use a RewriteCond with the %{HTTP_HOST}, %{SERVER_PORT}, or %{QUERY_STRING} variables respectively.
So, when in Directory and htaccess
context the prefix /www/folder1/
will be removed. Also remember when matching with RewriteRule
in Directory and htaccess
context, the pattern will never begin with /
.
So, your RewriteRule
Should be:
Options +FollowSymLinks
RewriteEngine On
RewriteRule (.*) /index.php?disp=$1 [QSA,L]