How do I redirect a dynamic subdomain also based on query string?
I have my site which redirects all *.domain.com calls to domain.com.
What I want to acheive is that first when the user enters a dynamic subdomain name he should be directed to its home page like
if user writes division1.domain.com
, then the site should point to page division.php?value=division1
, and when the user accesses division1.domain.com/news/newsdetails.php
then this should call the page news.php
with argument value=division1
. Similarly if I call the news page form the base url like domain.com/news/newsdetails.php
then this should not开发者_Go百科 include any arguments.
Here is the current htaccess code
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com/(news/newsdetails.\.php)$ [NC]
RewriteCond %1 !^www$ [NC]
RewriteRule ^([^/.]*)(.*)$ news.php?div=%1$1&filter=$2 [NC,QSA,L]
# For www.domain.com it should go to the index page
RewriteCond %{HTTP_HOST} ^(www\.)?domain.com$ [NC]
RewriteRule ^(.*)$ index.php [NC,L]
# For Accessing Divisions Page
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$
RewriteRule ^$ divisions.php?username=%1 [R,L]
Add:
# redirect ******XX.domain.com
# to domain.com/*******.php?value=******XX
# where XX is a number...
RewriteCond %{REQUEST_URI} !news/newsdetails\.php$ # not news page
RewriteCond %{HTTP_HOST}!^www\.domain\.com # prevent rewrite www
RewriteCond %{HTTP_HOST} ^(([^.]+)[0-9]+)\.domain\.com$ # catch subdomain
RewriteRule .* http://domain\.com/%2.php?value=%1 [R=301, L] # Redirect
# redirect ******.domain.com/news/newsdetails.php
# to domain.com/news.php?value=******
RewriteCond %{REQUEST_URI} news/newsdetails\.php$ # news page
RewriteCond %{HTTP_HOST}!^www\.domain\.com # prevent rewrite www
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$ # catch subdomain
RewriteRule .* http://domain\.com/news.php?value=%1 [R=301, L] # Redirect
# redirect domain.com/news/newsdetails.php
# to domain.com/news.php
RewriteCond %{REQUEST_URI} news/newsdetails\.php$ # news page
RewriteRule .* /news.php?value=%1 [L] # Redirect
to your htaccess file.
精彩评论