Jump to content

Yet Another Redirect Question


lordphate

Recommended Posts

Okay this may sound a little odd but here's what i'm wanting to find out:

 

I want http://www.domain.com/index.php?page=classifieds  to actually be  http://classifieds.domain.com/  sounds easy right? WRONG, because i ALSO want all the classifieds to be http://classifieds.domain.com/nameofclassified  INSTEAD OF http://www.domain.com/classifieds/nameofclassified    ALL while keeping the url as classifieds.domain.com (or classifieds.domain.com/nameofclassified)

 

Any help would be HIGHLY appreciated

Link to comment
Share on other sites

  • 2 weeks later...

I think you're making it too hard on yourself (I do this from time to time as well)..  The rewrite code I gave you does just what you're asking.  Let me break it down for you.

 

First we add the rewrite condition:

RewriteCond %{HTTP_HOST} classifieds.domain.com

 

This tells mod_rewrite to check for your third level domain "classifieds"

If it is then it moves on to test the next condition.

 

RewriteRule ^$ index.php?page=classifieds

 

Here we are telling mod_rewrite that if the url is blank (http://classifieds.domain.com/) re-write the url as index.php?page=classifieds

 

if the URL isn't blank mod_rewrite will not touch it.  That means that http://classifieds.domain.com/mydirectory will actually stay http://classifieds.domain.com/mydirectory.  So as long as http://classifieds.domain.com/ pulls up the directory for http://www.domain.com/ by default, no further rewites are needed.  However you could get as explicit as you want by simply adding additional rules like so:

 

RewriteRule ^(.*).html$ index.php?page=$1{QUERY_STRING} [L,NS]

 

The above would rewrite http://classifieds.domain.com/home.html to http://classifieds.domain.com/index.php?page=home

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.