Regex htaccess-重写以特定字符串结尾的URL并捕获唯一部分
我想将几个URL输入到一个php文件中,该文件将处理页面的内容,URL如下Regex htaccess-重写以特定字符串结尾的URL并捕获唯一部分,regex,apache,.htaccess,mod-rewrite,url-rewriting,Regex,Apache,.htaccess,Mod Rewrite,Url Rewriting,我想将几个URL输入到一个php文件中,该文件将处理页面的内容,URL如下 domain.com/fashion-registration domain.com/singing-registration 我想捕获以-registration结尾的URL,并将fashion或singing输入到页面中,但它似乎不起作用。这就是我试过的 RewriteRule ^(.*)$-registration category.php?link=$1 [NC,L,QSA] 你能试试下面的吗 Rewrite
domain.com/fashion-registration
domain.com/singing-registration
我想捕获以-registration
结尾的URL,并将fashion
或singing
输入到页面中,但它似乎不起作用。这就是我试过的
RewriteRule ^(.*)$-registration category.php?link=$1 [NC,L,QSA]
你能试试下面的吗
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/(.*)-registration/?$ [NC]
RewriteRule ^(.*)$ /category.php?link=%1 [NE,NC,L]
或者你也可以试着跟着,一个不重写
RewriteEngine ON
RewriteRule ^(.*)-registration/?$ /category.php?link=$1 [NE,NC,L]
OP尝试中的问题:因为您使用了
^(.*)$
,之后您在正则表达式中使用了-registration
,这就是为什么您的正则表达式永远不会匹配-registration
您可以尝试以下内容吗
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/(.*)-registration/?$ [NC]
RewriteRule ^(.*)$ /category.php?link=%1 [NE,NC,L]
或者你也可以试着跟着,一个不重写
RewriteEngine ON
RewriteRule ^(.*)-registration/?$ /category.php?link=$1 [NE,NC,L]
OP尝试中的问题:由于您使用了
^(.*)$
,之后您在正则表达式中使用了-registration
,这就是为什么您的正则表达式永远都不会匹配-registration
@VeeK,所以我在发布之前对它进行了测试,效果很好,请看这个curl-IL"http://localhost:80/fashion-登记“
------>位置:http://localhost/category.php?link=fashion
,它对我有效,请告知我。我的站点不在localhost的根目录下。我用RewriteBase
修复了它。如果可以的话,还有一个问题。如果url中有-
,则它不起作用。例如,/时装秀注册
。你能解决这个问题吗?@VeeK,在发布之前我已经测试过了,对我来说效果很好,请看这个curl-IL“http://localhost:80/fashion-注册“
----->位置:http://localhost/category.php?link=fashion
,它对我有效,请告知我。我的站点不在localhost的根目录下。我用RewriteBase
修复了它。如果可以的话,还有一个问题。如果url中有-
,则它不起作用。例如,/时装秀注册
。你能解决这个问题吗?