.htaccesss RewriteRule won't work

44 views Asked by At

I want rewrite

htttp://www.site.ru/company.html?name=bestcompany

to

htttp://www.site.ru/company/bestcompany.html

Please suggest where I was wrong. What I do:

RewriteRule ^company/([^/]*)\.html$ /company.html?name=$1 [L]

CMS modx, .htacces in root folder, full .htaccess code:

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]
1

There are 1 answers

3
anubhava On BEST ANSWER

Rearrange your rules like this:

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]