简体   繁体   中英

301 redirect an entire folder but keep dynamic urls intact

I have a directory that was mislabeled.

Example: www.example.com/badfolder

It should've been: www.example.com/goodfolder

Within the directory, there are tons of dynamic urls and friendly urls.

I'd like to put a line in my .htaccess file in the public_html folder that redirects to the new folder.

Therefore, it someone was navigating to: www.example.com/badfolder/page.php?id=123&x=5&y=10

It would redirect to: www.example.com/goodfolder/page.php?id=123&x=5&y=10

Is this correct?

RewriteEngine On
RewriteRule ^badfolder/(.*)?$ /goodfolder/$1 [R=301,NC,NE,L]

What you have works fine for me. You just need to make sure it's closer to the top of your htaccess file, above any other internally rewriting rules that you may have.

Alternatively, you can stick with mod_alias:

Redirect 301 /badfolder /goodfolder

and it'll do the same thing.

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