htaccess Elite

.htaccess tutorial


All times are UTC [ DST ]





Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Wildcard DNS and seo subdomain redirecting internally
PostPosted: 30 Jan 2007 11:24 
Offline

Joined: 30 Jan 2007 11:20
Posts: 33
Hi htaccessElite!

I have wildcard setup on my domain example.com, so anything.example.com goes to my docroot.

My question is I have a search.php file in my / directory, and I want people who goto example.com/search.php?q=yyyy:xxxx:
to
xxxx.example.com
or
xxxx-yyyy.example.com if the above example is not possible given the yyyy variable.


Top
 Profile  
 
 Post subject:
PostPosted: 30 Jan 2007 11:25 
Offline

Joined: 30 Oct 2006 19:55
Posts: 99
To redirect
http://example.com/search.php?q=yyyy:askapache:
==>
http://askapache.example.com/
Code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^([a-z]+\.)?(.+)\.com [NC]
RewriteCond %{REQUEST_URI} ^/search\.php [NC]
RewriteCond %{QUERY_STRING} ^q=([a-z]+):([a-z]+): [NC]
RewriteRule .* http://%4.%2.com/? [L,R=301]


Or to redirect
http://example.com/search.php?q=apachec ... :askapache:
==>
http://askapache-apachecategory.example.com/
Code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/search\.php [NC]
RewriteCond %{QUERY_STRING} ^q=([a-z]+):([a-z]+): [NC]
RewriteRule .* http://%2-%1.example.com/? [L,R=301]


Top
 Profile  
 
 Post subject:
PostPosted: 30 Jan 2007 11:28 
Offline

Joined: 30 Jan 2007 11:20
Posts: 33
Except I don't want a redirect, I want

xxxx-yyyy.example.com

to look exactly like

example.com/search.php?q=yyyy:xxxx:

as if the sub domain is the real URL. Internal redirection?


Top
 Profile  
 
 Post subject:
PostPosted: 30 Jan 2007 11:30 
Offline

Joined: 30 Oct 2006 19:55
Posts: 99
Internally (transparent to the user) redirects
Code:
http://apache-htaccess.example.com => /search.php?q=htaccess:apache:


Code:
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com [NC]
RewriteCond %{HTTP_HOST} ^([a-z]+)?-?([a-z]+)?\.example\.com$ [NC]
RewriteRule .* /search.php?q=%2:%1: [L]



Is that what you want!?


Top
 Profile  
 
 Post subject:
PostPosted: 30 Jan 2007 11:30 
Offline

Joined: 30 Jan 2007 11:20
Posts: 33
Perfect! Thankyou mod_rewrite!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron
Powered by phpBB