Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirecting a User

Status
Not open for further replies.

kbc1

Programmer
Feb 23, 2007
5
GB
Hi all,

I would like to find out how to do something that i see regularly on websites and need advice!

In many cases when you visit a website by typing in the domain only (i.e. you will see the URL automatically change to something like (for example!).

I need to do this for a small site I am working on and would like to know how to achieve it. I am guessing it maybe related to mod_rewrites or something but I have never really used this functionality before.

I know how to redirect the user in PHP by simply including a specific php file and use the exit(); statement immediately after, but I need to be able to changes the URL also in order to populate the REQUEST_URI server variable.

Any advice would be GREATLY appreciated.
K
 
Hope this helps. Note change the ip address to your host ip
Code:
<VirtualHost [b]192.168.0.1[/b]:80>
    ServerAdmin admin@domain.com
    ServerName [URL unfurl="true"]www.mydomain.com[/URL]
    ServerAlias mydomain.com
    
    Redirect / [URL unfurl="true"]http://www.mydomain.com/newwebpage[/URL]
</VirtualHost>

M. Brooks
 
Thanks mbrooks, but by adding that into my http.conf file my website no longer worked at all i.e. i received a 404 page not found error for all webpages.

I also need a solution that will allow me to apply it to a shared web server, and I am not sure if this solution would be applicable in that scenario would it?

 
If you want to use .htaccess, you can add this to the file:
Code:
RewriteEngine on 
RewriteRule ^$ /newdir/

You would put this .htaccess file in your docroot for example then 'newdir' would be the new directory you want to point to. This comes in very handy if you install a forum or blog and they get put in their own sub-directory. You simply replace 'newdir' with /wordpress/ or /phpBB/ or whatever. If you just want to make a different file name your index page, you could still use .htaccess but use the DirectoryIndex directive and add the file name to it.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top