简体   繁体   中英

301 redirect with wildcard in htaccess not working

All traffic will be directed from

https://oldsite.com/

to

https://www.newsite.com

I am looking for a 301 wildcard redirect solution for the following

https://oldsite.com/blog/*(the slug)

to

https://www.newsite.com/blog/*(matching slug)

Used htaccess file is:

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>

With your shown samples, please try following. Keep your domain redirection at the top of your htaccess file then keep other Rules. Also make sure to clear your browser cache before testing your URLs.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

##Have your domain changes rules here...
RewriteCond %{HTTP_HOST} ^oldsite\.com$ [NC]
RewriteRule ^  https://www.newsite.com%{REQUEST_URI} [NE,R=301,L]

RewriteRule ^index\.php$ - [L]

##Non existing files/directories rewrite rules here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.php [L]
</IfModule>

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