【问题标题】:PHP Redirect standard URLs to SEO URLsPHP 将标准 URL 重定向到 SEO URL
【发布时间】:2011-12-17 14:26:09
【问题描述】:

我目前使用以下重写规则:
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]

我想使用 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,以防输入的标题不正确)。

谢谢。

【问题讨论】:

    标签: php .htaccess seo


    【解决方案1】:

    在这里查看我的答案: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]
    

    【讨论】:

    • 不幸的是,这似乎不起作用。我在我在 OP 中发布的案例下方添加了代码(RewriteEngine On 也在那里),它不会将我从 books.php?b=1 重定向。
    猜你喜欢
    • 2019-10-28
    • 2015-05-29
    • 1970-01-01
    • 2015-01-07
    • 1970-01-01
    • 1970-01-01
    • 2017-04-20
    • 1970-01-01
    • 2018-07-01
    相关资源
    最近更新 更多