PHP 将标准 URL 重定向到 SEO URL

标签 php .htaccess seo

我目前使用以下重写规则:
RewriteRule ^books/([bc])/([0-9]+)/(.*)/page([0-9]+) books.php?type=$1&id=$2&title=$3&page=$4 [L]<br/> RewriteRule ^books/([bc])/([0-9]+)(.*) books.php?type=$1&id=$2&title=$3 [L]<br/> RewriteRule ^books/(.*) books.php?type=$1 [L]<br/> 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,以防输入的标题不正确)。

谢谢。

最佳答案

在这里查看我的回答:my .htaccess redirection fails

你会像这样重写它(省略标题 - 你需要 php):

RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/books\.php$
RewriteCond %{QUERY_STRING} ^([a-z])=([a-zA-Z0-9_-]+)$
RewriteRule ^(.*)$ http://www.domain.com/%1/%2? [R=302,L]

关于PHP 将标准 URL 重定向到 SEO URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7934816/

相关文章:

reactjs - React-snap 并注册 service worker

.htaccess - 使用 .htaccess 重定向到 https

php - 使用自定义参数导出数据 Laravel Excel

Phpseclib:部分文件下载

php - nginx + proxy pas - 504 网关超时,1 分钟 30 秒后超时。试过 proxy_read_timeout 但没有成功

wordpress - 在 htaccess 文件中阻止 IP 范围

.htaccess - htaccess 路由

html - 我可以标明我网站每个页面的语言,以便 Google 不会向用户显示外国内容吗?

html - 在 HTML5 中使用 H1 Logo

PHP - 猜测变量中存储的图像的 MIME 类型