Welcome to WebmasterWorld Guest from 54.198.164.83

Forum Moderators: Ocean10000 & incrediBILL & phranque

trying to smartly redirect

     
7:26 pm on Nov 21, 2017 (gmt 0)

Junior Member

Top Contributors Of The Month

joined:Sept 13, 2013
posts: 193
votes: 1


I'm having trouble moving domains, and doing a permanent redirection. Maybe someone can help. I'd like everyone going to a folder in my original domain
http://example.com/thisandthat*
(where * means anything attached to this URL string) to end up at my new domain at
http://example2.com/redirect.html
Where redirect.html is a page that says "You landed here because ...". I tried, in the .htaccess for my original domain, example.com, the command
RedirectPermanent "/thisandthat" "http://example2.com/redirect.html"
So I test it out by going to
http:/example.com/thisandthat/test.html
But the logs for my new domain say that this request was interpreted as
http://example2.com/redirect.html/test.html
which is nonsense. My new domain shrugs it off as a 404 error. I want ANY request for stuff in "thisandthat" to be redirected accordingly to redirect.html. Help!
7:41 pm on Nov 21, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:14608
votes: 598


Your primary mistake is using mod_alias (Redirect by that name). It doesn't combine well with mod_rewrite (RewriteRule, which you have surely also got somewhere).

Change your rule to mod_rewrite syntax and continue from there.

Now, if you were doing it in mod_alias, you would need to say RedirectMatch to allow an open-ended pattern. Otherwise, the core behavior of a mod_alias redirect kicks in: the rest of the path is reappended to the part you've changed. But it's really awfully unlikely that you are not using mod_rewrite at all; if nothing else, how do you handle domain-name-canonicalization redirects?
7:56 pm on Nov 21, 2017 (gmt 0)

Junior Member

Top Contributors Of The Month

joined:Sept 13, 2013
posts: 193
votes: 1


I'm sorry, Lucy can you be more specific?
RewriteEngine on
RewriteRule "/thisandthat" "http://example2.com/redirect.html"
Doesn't do the trick.
9:14 pm on Nov 21, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:14608
votes: 598


Unless the rule is lying loose in config (highly unlikely unless it's in a VirtualHost section), you have to omit the leading slash. The quotation marks are also unnecessary, and don't forget the flags. You need [R=301,L].
9:29 pm on Nov 21, 2017 (gmt 0)

Junior Member

Top Contributors Of The Month

joined:Sept 13, 2013
posts: 193
votes: 1


Yep, that got me what I want. Thank you!