Massive .htaccess Redirect - .htaccess

I got some problem on redirecting something.
I tried to use Redirect 301 /link/link/link to /link/link
Is there a way to make it more easier coz there are 100+ links I need to redirect.
Like this
/blog/category/energy-savings/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing
/blog/category/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/
/blog/category/uncategorized/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/about
/blog/category/uncategorized/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/about
/blog/category/uncategorized/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing
/blog/category/uncategorized/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/about
/blog/category/water-conservation/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing
/blog/category/water-conservation/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/plumbing/about
To the Homepage?
Thanks

The directive:
Redirect 301 /link/link/link /link/link
Doesn't do what you think it does. It's mapping to nodes together, meaning a request for:
/link/link/link/foo/bar.html
gets redirected to:
/link/link/foo/bar.html
So maybe you need to fix that. You could try:
RedirectMatch 301 ^/link/link/link/?$ /link/link
so the nodes aren't connected like in the Redirect directive. As for trying to "fix" this problem of yours, you can try:
RedirectMatch 301 ^/([^/]+)/([^/]+)/([^/]+)/([^/]+)/\4/ /
This redirects anything that looks like: /blah1/blah2/blah3/same/same/same/ etc. to the homepage at /. The \4 matches the 4th path in the URI, so if anything after the 3rd path repeats, then it redirects.

Related

.htaccess redirect / rewrite condition with exact match

I need to redirect a url like this:
https://zzz.com/Class/Today-Class-100
to
https://zzz.com/otherfolder/
BUT leave a url like this
https://zzz.com/de/Class/Today-Class-100
alone. Right after the .com we have language directories, and those should not redirect. Only the first one should - how do I redirect an EXACT URL and leave ones with any difference alone?
This did not work:
RedirectMatch 301 ^/Class/Today-Class-101$ https://zzz.com/otherfolder/
as it still redirected with a subfolder in front of
/Class/Today-Class-101$

Trailing slash must be present for .htaccess redirect 301 to take place - why?

I am trying to redirect the following:
Redirect 301 /fruit/ https://www.website.com/vegetables/
^ The above works great IF the user clicks a link. However, should the user type-in the URL and omit the trailing slash after 'fruit' then it throws a 404.
So, my question is, how do I make all reference to /fruit/ or /fruit work correctly under 301 protocol?
Thanks for all replies
Google was my friend: the answer is >
RedirectMatch 301 /fruit/?$ https://www.website.com/vegetables/

301 Redirects behaving strangely

Running into this issue where the redirect in the second line is redirecting to the URL in the first line.
Redirect 301 /academics/degrees http://mydomain.edu/folder1/location1/
Redirect 301 /academics/degrees/phd http://mydomain.edu/folder1/location2/
At first I thought it had something to do with the locations to be redirected containing hyphens, but haven't been able to find anything on that.
Does it have something to do with the locations to be redirected sharing the same folder/permalink structure?
I've never encountered this before and am totally lost. I tried RedirectMatch but that didn't have any effect.
It is because /academics/degrees matches both URLs and rule for /academics/degrees/phd never fires. Either change the order of your rule OR better use RedirectMatch with regex capability to match only desired URL pattern:
RedirectMatch 301 ^/academics/degrees/?$ http://mydomain.edu/folder1/location1/
RedirectMatch 301 ^/academics/degrees/phd/?$ http://mydomain.edu/folder1/location2/
Make sure to clear your browser cache before testing this change.

how to 301 redirect URL with %3E character

I have this weird URL, /andy-sixx-2012-short-hair%3Eandy. I've tried this:
Redirect 301 /andy-sixx-2012-short-hair%3Eandy http://mysite.com/page.html
but that fails. I can redirect something like /andy-sixx-2012-short-hairandy no problem so the issue seems to be the %3E character. Any help would be great. Thanks!
The URI is decodeded before modules like mod_alias or mod_rewrite gets to process them, thus you need to match against > and not %3E:
Redirect 301 /andy-sixx-2012-short-hair>andy http://mysite.com/page.html

htaccess Redirect 301 : mysite.com/sub/ to mysite.com/sub/home

my homepage url is like this http://mysite.com/sub/
I just want it to redirect to new url something like this http://mysite.com/sub/home?lang=en
here's my code
Redirect 301 /sub/ /sub/home?lang=en
Problem/error:
the new url becomes like this http://mysite.com/sub/home?lang=enhome
there's unnecessary home concatinated after en
how can I removed this? Or is there something wrong with my code?
don't know there's might be already same question like this
This is because the Redirect directive "connects" 2 path nodes, and you've got one inside the other (/sub/home is inside /sub). For example, if the directive looks like this:
Redirect 301 /a /b
This means when someone requests http://mysite.com/a/foo/bar they get redirected to http://mysite.com/b/foo/bar. What happens when you get redirected to /sub/home is that you get redirected again because /sub/home matches the pattern /sub, and the home gets appended, thus /sub/home?lang=enhome.
You can try using RedirectMatch instead, which doesn't "connect" path nodes:
RedirectMatch 301 ^/sub/?$ /sub/home?lang=en
Or mod_rewrite:
RewriteEngine On
RewriteRule ^/?sub/?$ /sub/home?lang=en [L,R=301,QSA]

Resources