Forum Moderators: phranque
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]
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.
...
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.
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.
...