【问题标题】:htaccess seo url friendly with \ and /htaccess seo url 对 \ 和 / 友好
【发布时间】:2015-04-17 06:58:14
【问题描述】:

我在我的网络中搜索轮胎,我有 3 个参数要搜索:宽度、切片和 koter(radius)

我希望在搜索后直接指向此 url: example.com/tires/width/sliceR/koter - > example.com/tires/205/55R/16

我从用户那里得到的值只是数字,比如: 宽度:205 切片:55 koter(半径):16

我写了这段代码:

RewriteRule ^tires/$ /tires.php [L]
RewriteRule ^tires/([0-9/]+)/([^/]+)/([0-9/]+)$ /tires.php?width=$1&slice=$2&koter=$3 [L]


RewriteCond %{QUERY_STRING} ^width=(\w+)&slice=(\w+)&koter=(\w*)$
RewriteRule ^ http://example/tires/%1\/%2\/%3? [R,L]

但它不起作用......我对最后一个网址中的 / 有疑问: http://example.com/tires/15/15R/15/ - 工作 http://example.com/tires/15/15R/15 - 不工作

而且,我对双数有疑问: example.com/tires.php?width=205&slice=55&koter=17.5 没有重定向到友好的网址。

谢谢你,对不起我的无知

【问题讨论】:

    标签: .htaccess url-rewriting seo


    【解决方案1】:

    您可以在 DOCUMENT_ROOT/.htaccess 文件中使用此代码:

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{THE_REQUEST} \s/+tires\.php\?width=([^\s&]+)&slice=([^\s&]+)&koter=([^\s&]+) [NC]
    RewriteRule ^ tires/%1/%2/%3? [R=302,L,NE]
    
    RewriteRule ^tires/$ tires.php [L]
    RewriteRule ^tires/([0-9.]+)/([^/]+)/([0-9.]+)/?$ tires.php?width=$1&slice=$2&koter=$3 [L,QSA]
    

    【讨论】:

    • 很好,您使用 302,+1。我相信你的意思是[0-9.]+ 也是 3 美元。半径也可以是一个浮点数。
    猜你喜欢
    • 2015-01-13
    • 2013-02-03
    • 2011-05-29
    • 2013-01-22
    • 2012-09-02
    • 2016-03-12
    • 2011-05-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多