我有一条规则.htaccess
,使文章的URL更加友好,以实现SEO之类的目的。
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(news-and-views)/(.+).php /$1/article.php?title=$2 [L]
哪个转换了此URL:
/news-and-views/going-for-brokering.php
在应用程序本身中对此:
/news-and-views/article.php?title=going-for-brokering
现在,我需要一个带有ID的URL,在标题之前像这样:
/news-and-views/123456789/going-for-brokering.php
所以我尝试了以下规则:
RewriteRule ^(news-and-views)/(.+)/(.+).php /$1/article.php?Id=$2&title=$3 [L]
但是,这不起作用,我是否误解了括号的使用,因为我认为括号之间的所有内容都被认为是右侧的变量?
我想这甚至可能是特定性较低的规则高于特定性更强的规则。
您需要注意规则的顺序,因为您的第一个规则也会匹配/news-and-views/123456789/going-for-brokering.php
。更改规则,如下所示:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(news-and-views)/([^/]+).php /$1/article.php?title=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(news-and-views)/([0-9]+)/([^/]+).php /$1/article.php?Id=$2&title=$3 [L]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句