Forum Moderators: phranque

Message Too Old, No Replies

another .htaccess problem, help!

more htaccess coding problems

         

mattym

12:05 pm on Dec 18, 2008 (gmt 0)

10+ Year Member



Hello

i am trying to set up a simple redirect so i can build a site on a domain, but if i use a 'normal' redirect i cant do it as the pages wont load as it is following the redirect, is it possible to allow 1 file to be accessed on the root site while all other traffic is sent away?

I have this as my redirect:
ErrorDocument 404 http://www.example.co.uk/404.htm
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com[NC]
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [R=301,L]
redirect 301 "/index.html" http://www.example.co.uk

the file i want to access is the index.php file on the .com domain..is it possible?
thanks in advance for your time and help

[edited by: jdMorgan at 12:38 am (utc) on Dec. 19, 2008]
[edit reason] example.co.uk & example.com [/edit]

Samizdata

12:52 pm on Dec 18, 2008 (gmt 0)

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



Welcome to Webmasterworld.

First, your ErrorDocument path should be relative:

ErrorDocument 404 /404.htm

Any files linked from the document should use absolute paths.

Next, your domain condition omits the "www" and has a backslash missing - if I understand your question correctly (no promises), you should be able to redirect all requests to index.php like this:

# Turn on mod_rewrite
RewriteEngine On

# Redirect all requests to root
RewriteCond %{HTTP_HOST} ^(www\.)example\.com [NC]
RewriteRule (.*) http://www.example.com/ [R=301,L]

# Set default order
DirectoryIndex index.php index.htm index.html

But you say you are building a site on the domain, so the question arises as to how YOU are going to access the rest of it while keeping everyone else out - and this is easy to accomplish if you have a static IP by making this the first condition:

RewriteCond %{REMOTE_ADDR} !^your\.IP\.address\.here

If you have a dynamic IP you would have to change this line each time.

Untested, and someone may well offer a better (or corrected) solution.

...

mattym

2:05 pm on Dec 18, 2008 (gmt 0)

10+ Year Member



hello

thanks for the reply..im interested in allowing the IP address as i think this could be the solution that i need, it will keep everyone else out and me in where i need to be, so i will play with that and see what can be done.

g1smd

11:16 pm on Dec 18, 2008 (gmt 0)

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



There's a question mark missing directly after the (www\.) part, if that part is supposed to be optional.

The redirect redirects all URLs to the root; in the post immediately above, whereas the OP did re-use the backreference in the original post.

There's a number of other errors throughout:

- Periods need escaping.
- Redirects need to be listed before rewrites.
- Never mix Redirect and RewriteRule in the same .htaccess file.

I am also still not completely clear on all the URL formats to be matched and to reject here.

Samizdata

12:05 am on Dec 19, 2008 (gmt 0)

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



There's a question mark missing

Oops... thank you.

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]

The redirect redirects all URLs to the root

That was my understanding of what the OP wanted to do - send all requests to root and serve index.php instead of another extension.

But understanding is not always my strong point.

...

g1smd

12:17 am on Dec 19, 2008 (gmt 0)

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



The data in the original question is far from complete.

There's no hope of getting anything to work, when what it has to do hasn't yet been sufficiently defined.

mattym

11:04 pm on Dec 24, 2008 (gmt 0)

10+ Year Member



the IP redirect works perfectly, so thank you, Happy Christmas