htaccess mod
这是我的htaccess代码:
RewriteEngine On RewriteRule ^s/(.*)/(.*) /index.php?search=$1&category=$2 [L,QSA] RewriteCond %{QUERY_STRING} ^search=([A-Za-z0-9+]+)$ RewriteRule ^(.*)$ /s/%1/? [R=301,L] RewriteCond %{QUERY_STRING} ^search=([A-Za-z0-9+]+)&category=([A-Za-z0-9+]+)$ RewriteRule ^(.*)$ /s/%1/%2/? [R=301,L]
我需要做一个这样的重写规则:
http://mywebsite.com/s/query+term => http://mywebsite.com/?search=query+term OR if there is a category http://mywebsite.com/s/query+term/Category => http://mywebsite.com/?search=query+term&category=Category
我还需要将所有旧网址重新导向新网址。
根据这条规则,我所能获得的所有内容都是让搜索词和分类名联合起来。 简而言之,就好像我总是:
http://mywebsite.com/?search=query+term/Category
如果我删除所有条件(RewriteCond),只留下重写规则并添加尾部斜线:
RewriteEngine On RewriteRule ^s/(.*)/(.*)/ /index.php?search=$1&category=$2 [L,QSA]
以直接的方式获得我感兴趣的网址,整个事情就会奏效。 但我不会有重定向..
所以我试图设置一个这样的规则:
RewriteEngine On RewriteRule ^s/(.*)/(.*)/ /index.php?search=$1&category=$2 [L,QSA] RewriteCond %{QUERY_STRING} ^search=([A-Za-z0-9+]+)$ RewriteRule ^(.*)$ /s/%1/? [R=301,L] RewriteCond %{QUERY_STRING} ^search=([A-Za-z0-9+]+)&category=([A-Za-z0-9+]+)$ RewriteRule ^(.*)$ /s/%1/%2/? [R=301,L]
但是通过这个规则,我得到了一个重定向循环。
您可以使用以下规则:
RewriteEngine on
#1--Redirect from "?search=foobar&cat=cat" to "/s/foobar/cat" --#
RewriteCond %{THE_REQUEST} /?search=([^&]+)&cat=([^s]+) [NC]
RewriteRule ^ /s/%1/%/%2? [NC,L,R]
#2--Redirect from "/?search=foobar" to "/s/foobar" --#
RewriteCond %{THE_REQUEST} /?search=([^/s]+) [NC]
RewriteRule ^ /s/%1? [NC,L,R]
#1--Rewrite "s/foobar/cat" to "/?search=foobar&cat=cat"--#
RewriteRule ^s/([^/]+)/([^/]+)/?$ /?search=$1&$category=$2 [NC,L]
#2--Rewrite "s/foobar" to "/?search=foobar"--#
RewriteRule ^s/([^/]+)/?$ /?search=$1 [NC,L]
链接地址: http://www.djcxy.com/p/36543.html
上一篇: htaccess mod