Mod rewrite 参数的mod重写规则
我有以下网址 我想将上面的url永久重定向到using.htaaccess文件。(apache服务器)Mod rewrite 参数的mod重写规则,mod-rewrite,Mod Rewrite,我有以下网址 我想将上面的url永久重定向到using.htaaccess文件。(apache服务器) 也请考虑有其他网址,但我不想触摸它们……像 www.localhost.com/message.php?id=12 www.localhost.com/editprofile.php?editname=first.last www.localhost.com/uploadphoto.php?username=first.last 谁能帮帮我吗。 提前谢谢。您可以尝试使用RewriteCond
也请考虑有其他网址,但我不想触摸它们……像
www.localhost.com/message.php?id=12
www.localhost.com/editprofile.php?editname=first.last
www.localhost.com/uploadphoto.php?username=first.last
谁能帮帮我吗。
提前谢谢。您可以尝试使用
RewriteCond
处理查询字符串,并将捕获的匹配传递给RewriteRule
。您必须排除重写规则中的任何.php
脚本,否则会对其他URL产生一些问题
不要忘记在您的RewriteRule
之后添加[QSA]标记,否则它将不会添加查询字符串参数
也许是这样做:
RewriteEngine on
#serve any existing php scripts as usual
RewriteRule ^([a-zA-Z0-9]+\.php) - [L]
#and now handle your specific stuff:
RewriteCond %{QUERY_STRING} ^([a-zA-Z0-9]+\./[a-zA-Z0-9]+)$
RewriteRule ^(%1)$ /profile.php?username=%1 [QSA]
我不测试它,但它应该是一个好的开始。关于如何编写和处理特定的重写用例,您可以阅读文档中的一些好东西。@Thierry…谢谢您的回答…但实际上我对mod rewrite的知识是空白的…如果您能告诉我应该如何实现这一点,那将是非常好的…我将尝试一下…让我们看看…非常感谢您@蒂埃里布
www.localhost.com/message.php?id=12
www.localhost.com/editprofile.php?editname=first.last
www.localhost.com/uploadphoto.php?username=first.last
RewriteEngine on
#serve any existing php scripts as usual
RewriteRule ^([a-zA-Z0-9]+\.php) - [L]
#and now handle your specific stuff:
RewriteCond %{QUERY_STRING} ^([a-zA-Z0-9]+\./[a-zA-Z0-9]+)$
RewriteRule ^(%1)$ /profile.php?username=%1 [QSA]