我想重写
HTTTP://www.site.ru/company.html名称= bestcompany
到
HTTTP://www.site.ru/company/bestcompany.html
请说明我错在哪里。我做了什么:
RewriteRule ^company/([^/]*)\.html$ /company.html?name=$1 [L]
CMS modx,根文件夹中的.htacces,完整的.htaccess代码:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.site\.ru [NC]
RewriteRule (.*) http://www.site.ru/$1 [R=301,L]
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
RewriteRule ^company/([^/]*)\.html$ /company?name=$1 [L]
答案 0 :(得分:0)
重新排列您的规则:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.site\.ru [NC]
RewriteRule (.*) http://www.site.ru/$1 [R=301,L,NE]
RewriteCond %{THE_REQUEST} \s/+(company)(?:\.html)?\?name=([^\s&]+) [NC]
RewriteRule ^ /%1/%2.html? [R=302,L,NE]
RewriteRule ^company/([^./]+)\.html$ /company?name=$1 [L,NC,QSA]
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]