PHP 将标准 URL 重定向到 SEO URL
我目前使用以下重写规则:
RewriteRule ^books/([bc])/([0-9]+)/(.*)/page([0-9]+) books.php?type=$1&id=$2&标题=$3&页=$4 [L]
RewriteRule ^books/([bc])/([0-9]+)(.*) books.php?type=$1&id=$2&title=$3 [L]
RewriteRule ^books/(.*) books.php?type=$1 [L]
RewriteRule ^books books.php [L]
我想使用 htaccess 或 PHP 添加的是从标准 URL 格式到 SEO URL 格式的重定向。
例如:books.php?b=1
=>
books/b/1/book-title
books.php?c=1
=>
books/c/1/category-title
如果这可以使用 htaccess 完成,那就没问题了,我并不绝对需要标题,无论如何我都会使用 PHP 处理标题(如果输入的标题不正确,则重定向到正确的 URL)。
谢谢。
I currently use the following rewrite rules:RewriteRule ^books/([bc])/([0-9]+)/(.*)/page([0-9]+) books.php?type=$1&id=$2&title=$3&page=$4 [L]
RewriteRule ^books/([bc])/([0-9]+)(.*) books.php?type=$1&id=$2&title=$3 [L]
RewriteRule ^books/(.*) books.php?type=$1 [L]
RewriteRule ^books books.php [L]
What I'd like to add, either using htaccess or PHP, is a redirect from a standard URL format to an SEO URL format.
For example:books.php?b=1
=>
books/b/1/book-title
books.php?c=1
=>
books/c/1/category-title
If this can be done using htaccess it's fine, I don't absolutely need the title, I handle the title using PHP anyway (to redirect to the correct URL in case the title that's entered is incorrect).
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这里查看我的答案: 我的 .htaccess 重定向失败
你会像这样重写它这个(省略标题 - 你需要 php ):
See my answer here: my .htaccess redirection fails
You'd rewrite it like this (leaving out the title - you'd need php for that):