繁体   English   中英

RewriteRule:在URL中移动ID文章

[英]RewriteRule: move id article in url

我想将帖子ID移到网址中的最后一个位置。 像这样:

http://www.mysite.com/news/123-post.html

http://www.mysite.com/news/post-123.html

原始htaccess

RewriteRule ^([^.]+)/([0-9]+)-(.*).html$ index.php?newsid=$2&seourl=$3&seocat=$1 [L]

我改为

RewriteRule ^([^.]+)/(.*)-([0-9]+).html$ index.php?newsid=$2&seourl=$3&seocat=$1 [L]

并在浏览器中粘贴新的URL http://www.mysite.com/news/post-123.html ,但是它不起作用

您已交换news idseo url参数。 您必须在规则中做同样的事情。

此规则(新规则)

RewriteRule ^([^.]+)/(.*)-([0-9]+).html$ index.php?newsid=$2&seourl=$3&seocat=$1 [L]

应该看起来像这样

RewriteRule ^([^.]+)/(.*)-([0-9]+).html$ index.php?newsid=$3&seourl=$2&seocat=$1 [L]

$2现在进入了seourl$3现在进入了newsid 否则,您将遇到问题。

另外,如果您希望seourl仅位于同一文件夹而不是整个路径中,则可以通过确保seourl不包含任何斜杠( / )来优化规则。

RewriteRule ^([^.]+)/([^/]+)-([0-9]+).html$ index.php?newsid=$3&seourl=$2&seocat=$1 [L]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM