In .htaccess, how do you 301-redirect dynamic pages?
For example, what if I wanted a rule that made www.domain.com/SomeFolder/theThing redirect to www.domain.com/theThing?
I just want to remove the /folder and keep everything else. I already tried but no success.
EDIT:
I’m going to try be clearer. I have:
- http://www.domain.com/SomeFolder/theThing
- http://www.domain.com/SomeFolder/AnotherThing
- http://www.domain.com/SomeFolder/AndOneMoreThing
- ..and etc etc.
I want to remove this SOMEFOLDER because all those links were moved to index. But there’s a lot of them and I was thinking about doing it automatically using dynamic redirect 301.
This is how you can do it.
Using php:
Using htaccess:
Create a .htaccess file with the below code, it will ensure that all your directories and pages of your old domain will get correctly redirected to your new domain.
The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)
In addition to the redirect I would suggest that you contact every backlinking site to modify their backlink to point to your new website.
Note: This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.
Refer this for more methods