[英]URL Mod-Rewrite
我目前有一个有效的网址:
http://example.com/security-services.php?service=fixed-camera-surveillance
然后我让PHP说, $_REQUEST['service']
做一些事情...
但是,如果URL如下所示,我想实现相同的功能:
http://example.com/security-services/fixed-camera-surveillance
谢谢!
像这样的.htaccess
文件应该可以做到。
Options +FollowSymLinks
RewriteEngine On
RewriteRule security-services/(.*)/? security-services.php?service=$1 [L]
说security-services/(.*)/?
匹配浏览器中的URL并将其重写为security-services.php
。
关键部分是(.*)
,它捕获URL的该部分并将其作为GET值传递给PHP脚本。
尝试以下规则:
RewriteEngine on
RewriteRule ^security-services/([^/]+)$ security-services.php?service=$1 [L]
[^/]+
描述了/security-services
(…)
形成匹配的组,然后可以在替换中使用$1
引用的下一个路径段。
而且,如果您想对任何一种…-service.php
文件进行更一般的介绍:
RewriteEngine on
RewriteRule ^([^/-]+)-services/([^/]+)$ $1-services.php?service=$2 [L]
您可以创建如下规则:
RewriteRule ^security-services/(.*)/? /security-services.php?service=$1
如果您使用的是.conf文件,请将^
更改为^/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.