Forum Moderators: phranque

Message Too Old, No Replies

redirect from index.php to index.html

how to code the redirect

         

mattym

12:08 pm on Dec 29, 2008 (gmt 0)

10+ Year Member



hello

i have to redirect punters to the index.html file on a site, i have successfully set up a redirect to a different site, while allowing my own IP in to the index.php file, but now i want to simply redirect everyone else to index.html but i cant get it to work!

this is the working redirect to send them elsewhere

RewriteCond %{HTTP_HOST} ^(www\.)?currentsite\.com [NC]
RewriteRule ^(.*)$ [elsewhere.co.uk...] [R=301,L]
Redirect 301 "index.php" [elsewhere.co.uk...]

the above sends people away to the elsewhere site, but now i just want them to go to index.html

thanks for your time...

jdMorgan

4:52 pm on Dec 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Don't mix mod_rewrite and mod_alias (Redirect 301) directives if you need to control order of execution.

Generally, if you use mod_rewrite for *any* redirects, then your should use it for *all* redirects.

This is because, on any given server, each module looks at your directives in turn, executing only the directives that it understands. So, the directives in your .htaccess file are *not* executed sequentially, but rather in per-module order. And unless you configured the server, you cannot know whether mod_rewrite or mod_alias directives will execute first. And if you change hosts, this could change as well...

Jim

mattym

5:15 pm on Dec 29, 2008 (gmt 0)

10+ Year Member



hi Jim

ok that makes sense i think, but how can i write it

jdMorgan

5:26 pm on Dec 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know. Your description of your goals is at best confusing, and there are no example URL-paths and their associated filepaths to be seen...

Please post your best-effort code --with comments-- as a basis for discussion. As you know, we'll be happy to help you get your own code working, but we don't offer a 'free coding service' here.

Jim

mattym

5:40 pm on Dec 29, 2008 (gmt 0)

10+ Year Member



this is the code

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [R=301,L]
Redirect 301 "index.php" http://www.example.co.uk

i just changed the url to anonymous ones. I also have a little bit before that that allows my IP address access

what i want to do, is redirect people to index.html on the domain www.example.com while allowing myself access to index.php, the domain will be example.com

i have tried a lot of messing about with this over the course of today, but all i manage to do is get server configuration errors or a loop. I realise this isnt a free coding service, and i apologise for using it as one.

[edited by: jdMorgan at 6:30 pm (utc) on Dec. 29, 2008]
[edit reason] No URLs. Please see terms of Service and Forum Charter. [/edit]

g1smd

9:18 pm on Dec 29, 2008 (gmt 0)

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



As stated above, do not mix Redirect and RewriteRule in the same file. Use RewriteRule for both.

Add a blank line between each block and add a # comment to each block to explain what it does.

mattym

9:36 pm on Dec 29, 2008 (gmt 0)

10+ Year Member



i found a way to make this work now.

g1smd

9:43 pm on Dec 29, 2008 (gmt 0)

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



Let's see the code, as there are likely several ways to improve it.

mattym

10:21 pm on Dec 29, 2008 (gmt 0)

10+ Year Member



i couldnt do what i wanted, so i created a new file on a seperate site and redirected to it

RewriteCond %{REMOTE_ADDR} !^my\.ip\.address\.here
RewriteRule (.*) http://www.example.co.uk/example.html$1 [R=301,L]
RewriteRule /index.php$ http://www.example.co.uk/example.html [R=301,L]

i dont 'do' coding, i do this to save the company some money, so i expect its horribly wrong, which is why i posted here, i wasnt asking for someone to code it, i was asking for a little help, but eventually after a lot of frustration, time and googling, i found something that worked.

However

Any improvements would be gratefully received.

g1smd

11:28 pm on Dec 29, 2008 (gmt 0)

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



Do yourself a big favour and break the code up into blocks, each with a comment as to what the block does.

What is the $1 on the end of the second line for? The usage doesn't look correct.

Escape the period on the left side of the last line.

mattym

11:51 pm on Dec 29, 2008 (gmt 0)

10+ Year Member



i have no idea what the $1 is for, it was on the google result. As i said, i have no idea about this kind of thing, baisc php and html are my limit. thanks anyway

g1smd

12:16 am on Dec 30, 2008 (gmt 0)

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



You are modifying server configuration code with these changes.

A simple typo could make your site inaccessible to Google, or to all customers using a certain type of browser, or any other such disaster.

You need to be very clear as to what every bit of every line of code is supposed to do, and what it actually does, before making any such changes to your site.

mattym

9:45 am on Dec 30, 2008 (gmt 0)

10+ Year Member



for the time being i just want a redirect, i have no intention of submitting the link to google until i have the site finished. I will look up the code ive used and see if i can find what it means and what it should say.