我想做一些网址重写
http://www.domain.com/products/feed.php?keywords=*somewords*
=>
http://subdomain.domain.com/products/feed/*somewords*
我已经设置了htaccess
RewriteRule 301 products/feed.php?keywords=(.*?) http://subdomain.domain.com/products/feed/$2.xml
但它看起来不起作用,如何做出正确的写作?感谢。
答案 0 :(得分:1)
您可以使用此.htaccess
:
RewriteEngine on
RewriteCond %{QUERY_STRING} keywords=([^&]+) [NC]
RewriteRule ^products/feed\.php$ http://subdomain.domain.com/products/feed/%1 [NC,NE,L,R=301]
答案 1 :(得分:0)
您可以在DOCUMENT_ROOT/.htaccess
文件中使用此代码:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?domain].com$ [NC]
RewriteCond %{THE_REQUEST} \s/+(products/feed)\.php\?keywords=([^\s&]+) [NC]
RewriteRule ^ http://subdomain.domain.com/%1/%2? [R=302,L,NE]
您还需要在子域名的根目录.htaccess中使用此规则:
RewriteEngine On
RewriteBase /
RewriteRule ^(products/feed)/([^/.]+)/?$ $1.php?keywords=$1 [L,QSA,NC]