Forum Moderators: phranque

Message Too Old, No Replies

redirect htaccess help

redirect htaccess help to redirect 1 specific URL to another

         

mh_and

4:11 pm on Sep 19, 2012 (gmt 0)

10+ Year Member



Hi,

Can someone please help me to write couple of lines of code for my htaccess file. I'm not a programmer and this is really a small thing I want to accomplish myself on a way of understanding more of that coding.

So i have a wordpress site with 2 URLs that i want to redirect (as i understand it) to homepage

example.com/URL1/
example.com/URL2/

This are wordpress pages and each of them has subpages.

example.com/URL1/URL1-1/URL1-1-1/
example.com/URL2/URL2-1/URL2-1-1/

etc...

I'm putting a simple redirect rule

Redirect permanent /URL1/ http://www.example.com/
Redirect permanent /URL2/ http://www.example.com/

which works, but unfortunately it also redirects its subpages to homepage as well, i.e. automatically redirects this example.com/URL1/URL1-1/URL1-1-1/ to example.com

Can someone please specify a proper expression when only the specified URL will be redirected.

I've read a lot on using regex but couldn't form the working line of code.

Also for more knowledge and information what will be better for this case - redirecting or rewriting (sorry for this very newbie and basic question).


Thanks

wilderness

4:29 pm on Sep 19, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Most WP sites are run on PHP, which utilizes query strings, that you have not provided an explanation of in your examples.

There are literally thousands of previous examples of query strings rewrites and/or redirects for PHP strings in the forum archives.

g1smd

4:30 pm on Sep 19, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Use a RewriteRule (not RedirectMatch) as a redirect and use anchroring on the patterns to restrict exactly which requests are redirected.

mh_and

4:40 pm on Sep 19, 2012 (gmt 0)

10+ Year Member



@wilderness I did go through about 100-150 threads in the forum not mentioning so many google searches, I've described my problem and couldn't find a solution to it.

@g1smd can you specify a little more. I'm not familiar with the code itself.

thanks

lucy24

8:34 pm on Sep 19, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Go back and look at some of those 150 earlier threads, this time keeping your eyes peeled for the word "Rewrite". It will occur in at least 140 of them.

And then you can slowly start reading the ultimate authority [httpd.apache.org]. (Link is to 2.2 version. Version 2.4 may have some new bells & whistles but I don't think they've eliminated anything from 2.2 mod_rewrite.) Don't try to assimilate the whole thing in one gulp. Apache pages tend to be alphabetic rather than thematic, so top-to-bottom is not necessarily the most useful way to go. RewriteCond and RewriteRule are all most people need.

There's a good deal of overlap between mod_alias (Redirect by that name) and mod_rewrite (which can do both Rewrites and Redirects). But one fundamental difference is that mod_alias reappends the rest of the path, while mod_rewrite throws away anything you haven't explicitly captured. This in turn means that closing anchors $ are only safe in mod_rewrite. And this, in turn again, may mean that you should replace all your current Redirects with the Rewrite equivalent. This is not hard.

mh_and

7:04 am on Sep 20, 2012 (gmt 0)

10+ Year Member



Very easy.

Thank you

lucy24

7:49 am on Sep 20, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think that was sarcasm.

Oh, and when I said "This is not hard" I was referring specifically to the mechanics of converting an existing htaccess from mod_alias (Redirect 301...) to mod_rewrite (Rewrite Rule ... [R=301]) ;)