简体   繁体   中英

htaccess 301 redirect issues

Problem: I just did a major update to my companies website and trying to get some redirects to work. Right now if I have

Redirect 301 folder1/oldFile1.html http://www.mysite.com/newFolder1/newFolder2/newFile.html

and when you got to the new set up, I get this instead with a 404

http://www.mysite.com/newFolder1/newFolder2/newFile.htmloldFile.html

any ideas what is causing this?

Note: this only appears to happen to files that are moving from a 1 folder structure to a 2 folder structure.

RewriteOptions inherit
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^mysite.com [nc]
rewriterule ^(.*)$ http://www.mysite.com/$1 [r=301,nc] 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html?\ HTTP/
RewriteRule ^(.*)index\.html?$ http://www.mysite.com/$1 [R=301,L]

Don't mix mod_rewrite rules with mod_alias rules.

Use this instead:

RewriteOptions inherit
Options +FollowSymlinks
RewriteEngine on

RewriteCond %{http_host} ^mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,NC,L] 

RewriteCond %{THE_REQUEST} \s/.*index\.html?\ HTTP/
RewriteRule ^(.*)index\.html?$ http://www.mysite.com/$1 [R=301,L]

RewriteRule ^folder1/oldFile1\.html$ /newFolder1/newFolder2/newFile.html? [R=301,L]

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