简体   繁体   中英

multiple .htaccess rewrite rule failing

I am trying to create .htaccess to create friendly url.

I have made some of the urls work but the others not working. I am using the following code in .htaccess file.

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.airporttransfer4u.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.airporttransfer4u.co.uk/$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^195\.20\.236\.228
RewriteRule (.*) http://www.airporttransfer4u.co.uk/$1 [R=301,L]

ErrorDocument 404 /404.php 


RewriteBase /
RewriteCond %{REQUEST_URI} !^/admin/
 RewriteCond %{REQUEST_URI} !\.(gif|jpg|png|css|js|etc|flv|swf|mp4|mov)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]
RewriteRule ^recover/([^/]*)$ /recover.php?mode=$1 [L,QSA]

The url for recover.php is failing but index.php rule is working. Recover.php rule directing to 404 page.

I also have multple variable urls to convert to friendly url. Example

index.php?p=blog_item&id=52

Any idea why it is failing?

Have your rules in this order:

ErrorDocument 404 /404.php 
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.airporttransfer4u\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://www.airporttransfer4u.co.uk/$1 [L,R=301]

RewriteRule ^recover/([^/]+)/?$ /recover.php?mode=$1 [L,QSA]

RewriteCond %{REQUEST_URI} !^/admin/
RewriteCond %{REQUEST_URI} !\.(gif|jpg|png|css|js|etc|flv|swf|mp4|mov)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?p=$1 [L,QSA]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM