我不擅长 Apache URL 重写。我想在这里做一些重写。
http://www.mydomain.com/item/search?words=something&number=1
=>
http://www.mydomain.com/item/search/something/1
并且也应该避免http://www.mydomain.com/search/something/1
=> http://www.mydomain.com/item/search/something/1
(如果没有/item/
添加它)
这是我的重写代码。
RewriteRule ^search/(.*)/(.*)/?$ /item/search/$1/$2 [L,R=301]
RewriteRule ^(item/search)/([^/]+)/(\d+)/?$ item/search?words=$2&number=$3
它显示404
:(
更新:这是我所有的 .htaccess 文件:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^comment/(\d+)/?$ /post/comment/$1 [L,R=301]
RewriteRule ^(post/comment)/(\d+)/?$ post/comment?comment=$2
RewriteRule ^rss/(.*)/?$ /item/rss/$1 [L,R=301]
RewriteRule ^(item/rss)/(.*).xml/?$ item/rss.php?rss=$2
RewriteRule ^search/(.*)/(.*)/?$ /item/search/$1/$2 [L,R=301]
RewriteRule ^(item/search)/([^/]+)/(\d+)/?$ item/search?words=$2&number=$3
RewriteCond %{http_host} ^mydomain.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress