我有这个.htaccess url重写代码:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d -> important only if pagination is available
RewriteRule ^(article|gallery|news)/(.*)/(\d+)/(.*)/$(.*) index.php?page=$1&type=$2&id=$3&title=$4&page=$5&lang=en [NC,L,QSA]
这对我来说很糟糕,并且像这样重写网址:
mydomain/news/view/150/title.html/
和分页(只有在分页时才重要)
mydomain/news/view/150/title.html/12
现在我需要从第一个网址的末尾删除/
,如下所示:
mydomain/news/view/150/title.html
如何解决这个问题?!
答案 0 :(得分:0)
您可以使用2条规则:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# no paging URL
RewriteRule ^(article|gallery|news)/([^/]+)/(\d+)/([^/]+)/?$ index.php?path=$1&type=$2&id=$3&title=$4lang=en [NC,L,QSA]
# paging URL
RewriteRule ^(article|gallery|news)/([^/]+)/(\d+)/([^/]+)/(\d+)/?$ index.php?path=$1&type=$2&id=$3&title=$4&page=$5&lang=en [NC,L,QSA]
另请注意,您有2个参数page=
,我已将第一个参考重命名为path
,您可以根据需要进行更改。