Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex htaccess-重写以特定字符串结尾的URL并捕获唯一部分_Regex_Apache_.htaccess_Mod Rewrite_Url Rewriting - Fatal编程技术网

Regex htaccess-重写以特定字符串结尾的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

我想将几个URL输入到一个php文件中,该文件将处理页面的内容,URL如下

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中有
-
,则它不起作用。例如,
/时装秀注册
。你能解决这个问题吗?