Forum Moderators: phranque

Message Too Old, No Replies

Redirect home page

but leave everything else alone

         

lorax

5:43 pm on Nov 26, 2014 (gmt 0)

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



I have a need to occasionally redirect the home page of our main website to another site (in emergency situations). I want all other pages below the home page to still be accessible without redirect. I've been trying to get the Regex in place for this but I'm not having much luck. I was thinking that if I determined if the URL had anything after the .tld/ then it should be allowed to pass. If not, then redirect. So I was trying to use:

http://www.thedomain.tld/(?![a-z])

But it redirects everything.

lucy24

9:35 pm on Nov 26, 2014 (gmt 0)

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



What's the full rule? Is this happening in mod_rewrite, mod_alias or something else?

You need anchors at both ends; no need for a lookahead. If the rule is located in htaccess or in a <Directory> section, the RegEx looks like this

^(index\.html)?$


replacing "index.html" with the actual name of your root index file if you use a different extension. That's an optional extra for search engines and type-ins.

It makes vastly more sense to apply the rule only to requests for the root, and make your RegEx on that premise, rather than do it the other way around. If you're in mod_rewrite, put the rule after anything with an [F] flag so it doesn't override existing lockouts. Leave the rule in place permanently; just # comment it out when not needed.

Leosghost

9:46 pm on Nov 26, 2014 (gmt 0)

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



You could equally well do this without .htaccess..make a dummy "contentless" index page..indexx.html.with a php redirect script as first thing and only thing in it..
Then when you need to redirect..you rename index to indexy.html and indexx.html to index.html

and you can still do what Lucy24 suggests here..:)

replacing "index.html" with the actual name of your root index file if you use a different extension. That's an optional extra for search engines and type-ins.

lorax

2:26 pm on Nov 27, 2014 (gmt 0)

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



I'm using the Redirection plugin for WordPress which allows Regex. I want to use this because the changeover has to made as simple as possible. There is no file referenced in the URL. It resolves to /

Thanks to you both. I'll go play and let you know how I make out.

not2easy

3:49 pm on Nov 27, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



But in WordPress your "index.php" URL sets the URLs for all your taxonomy. Unless the WP is in a subdirectory, then you could address it in the WP settings, unless WP content is used for the home page.

Leosghost

4:07 pm on Nov 27, 2014 (gmt 0)

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



I put forward my "alternative" for those who do not use wordpress ( I know that it wouldn't work for the way wordpress works, although it can be "adapted" for some php "framework sites, such as those which use "codeigniter" )..It was more for those who seeing the word .htaccess tend to go "tharn" and seeing .htaccess with "redirect home page" their legs give out entirely and they need to go for a lie down..;)

They may be reading, but not posting ..

lucy24

7:35 pm on Nov 27, 2014 (gmt 0)

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



those who seeing the word .htaccess tend to go "tharn"

Alas I am not up to date on French expletives :(

Leosghost

7:46 pm on Nov 27, 2014 (gmt 0)

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



[urbandictionary.com...] "tharn" :)
The French can't say words which have th..they have some words which contain th..but cannot say them..what they do say instead..cracks me up every day "Mr Smith" and "smoothies" being hilarious..;)))

lucy24

5:56 am on Nov 28, 2014 (gmt 0)

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



The French can't say words which have th..

Er... you did know that I know that, didn't you? One never knows when the <fe> markup is called-for.

what they do say instead

I went to grad school with someone who grew up anglophone in Montreal. In consequence she did a fair amount of translating. The one I remember most vividly was her description of the Egyptologist who rendered "Thoth" as something like söss.

Returning to the topic at hand...

I think it's pretty funny to propose using php as an alternative to dealing with htaccess :) "tharn", eh?

lorax

5:06 pm on Nov 29, 2014 (gmt 0)

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



But in WordPress your "index.php" URL sets the URLs for all your taxonomy.

Not when permalinks are set /%postname%/ then index.php never shows in the URL.

lorax

4:23 pm on Dec 1, 2014 (gmt 0)

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



Still could get it to work properly so I ditched the plugin and wrote a conditional in the functions.php file.


if (get_option('page_on_front') == 'theid#' && strlen($_SERVER["REQUEST_URI"]) <= 1 ) {
$location = 'http:/[smilestopper/the_url_to_send_to/';
wp_redirect( $location );
exit;
}


If the home page is set to 'theid#' AND the length of the URI string after the TLD is 1 or less - then send the user to the emergency website.