[英]Removing page query string .htaccess
我有一个创建SEO URL的.htaccess文件。 例如,假设丑陋的URL为: example.com/stories?url=hello-world&page=5
url= example.com/stories/hello-world/5
example.com/stories?url=hello-world&page=5
,URL变为example.com/stories/hello-world/5
这可以完美地工作,但是对于第一页,我希望URL不显示页码。 例如,我希望像example.com/stories/hello-world/1
这样的URL为example.com/stories/hello-world
我该如何做?
当前的.htaccess
RewriteEngine On
RewriteBase /stories/
RewriteCond %{THE_REQUEST} /\?url=([^&\s]+)&page=([0-9]+) [NC]
RewriteRule ^ %1/%2? [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?url=$1&page=$2 [L,QSA]
像这样尝试
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# for hello world first page we are giving static value 1 to page.
RewriteRule ^([\w-]+)/?$ index.php?url=$1&page=1 [QSA,L]
# for others we are getting dynamic value.
RewriteRule ^([\w-]+)/([\d]+)$ index.php?url=$1&page=$2 [QSA,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.