[英]htacess how to convert two query strings to one url
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^news/([^/]+) /casino2/newsdetail.php?newsid=$1 [NC]
当前正在使用上面的代码将http://localhost/casino2/newsdetail.php?newsid=3
为http://localhost/casino2/news/3
现在我http://localhost/casino2/news/3
两个查询字符串中提取一个网址是什么问题例如,如果url是localhost/casino2/newsdetail.php?newsid=3
& pagename=article
则url应该是localhost/casino2/news/article
可以吗?
首先,这些规则似乎与您要说的相反—即它们将“ / localhost / casino2 / news / 4711”重写为“ /casino2/newsdetail.php?newsid=4711”。
只要这是您的真实意思,您需要做的就是将两个项目保存到两个变量中,而不是仅将一个项目保存到一个变量中,如下所示:
RewriteRule ^news/([^/]+)/([^/]+) /casino2/newsdetail.php?newsid=$1&pagename=$2 [NC]
如果newsid始终为1,则无需将其传递给php,只需在替换中创建它,就像这样
RewriteRule ^news/([^/]+) /casino2/newsdetail.php?newsid=1&pagename=$1 [NC]
这将创建以下重写:
/ news / article-> /casino2/newsdetail.php?newsid=1&pagename=article / news / somethingelse-> /casino2/newsdetail.php?newsid=1&pagename=article
但是,如果您希望能够选择其他新闻ID,则需要将其传递到某个地方-作为URL的一部分或作为查询字符串。
需要明确的是,规则的应用方式是
RewriteRule "What the URL looks like in the browser" "What my web server expects"
如果遇到问题,我强烈建议您打开很多调试日志记录,这将是很大的帮助。 相关的配置行是
RewriteLog /path/to/logfile
RewriteLogLevel 3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.