简体   繁体   中英

htaccess RewriteCond and RedirectMatch

I have enabled RewriteEngine within my .htaccess file. I have a condition to remove the "www" from any request. This works just fine. However I am also using RedirectMatch to do a 301 redirect. This works as well except that the request URI from the original incoming url is appended to the end of the url which I am 301 redirecting to.

Input URL:

http://www.example.com/newplate

Output URL:

http://example.com/contact/motorv.php?/newplate

Existing .htaccess file

AddOutputFilter INCLUDES .shtml .html .htm .php


RewriteEngine On
RewriteOptions inherit
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,L]


#straight 301 redirects
RedirectMatch 301 ^/newplate(.*) /contact/motorv.php


#if request is not an existing file or directory then redirect to
#codeigniter boot.php file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ boot.php?/$1 [L,QSA]

How should this issue be resolved? Is there something I have overlooked or written incorrectly?

You can use:

#straight 301 redirects
RewriteRule ^newplate(.*) /contact/motorv.php [NC,L,R=301]

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