问题
I am not really familiar with apache mod_rewrite
.
I have url parameters such as {domain}/index.php?blog=5
I simply want to make it {domain}/home.php?client=5
Is it a task as simple as it sounds and can anyone help?
回答1:
The following might work, give it a try
RewriteCond %{REQUEST_URI} ^/home.php [NC]
RewriteCond %{QUERY_STRING} client=([0-9]+) [NC]
RewriteRule (.*) http://%{REMOTE_HOST}/index.php?blog=%1 [L]
回答2:
That seems pretty simple, to be honest — once you get your head into mod_rewrite
, it's not that complex.
It sounds like you want to add
RewriteEngine on
RewriteRule ^/index.php?blog=(.+)$ /home.php?client=$1
to your configuration.
Some caveats:
- If you are putting this in a
.htaccess
file, then remove the/
from theRewriteRule
line. - If you want to make this case-insensitive, add
[NC]
to the end of that same line. - If you want users to see the URL change (so sending a
302 Found
redirection to the browser), then add[R]
to the end of theRewriteRule
line. - If you want both a
302 Found
and for the URL to be case-sensitive, combine the two instructions as[NC,R]
at the end of theRewriteRule
line.
It's definitely worth reading the mod_rewrite docs, but the rule above should be all you need for this use-case.
来源:https://stackoverflow.com/questions/2920816/beginners-apache-mod-rewrite-assistance