.htaccess subdomain argument not available in query string

I wrote the following rules in .htaccess

RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com RewriteCond %1 !^www$ [NC] RewriteCond %{REQUEST_URI} ^/news/news-details\.php$ RewriteRule (.*) news.php?div=%1 

What he does is pass the request to the news.php file with a div variable equal to news/news-details.php . I don't need a div to be like that. I need the value of the subdomain written in the domain, for example, if the user comes from user.domain.com/news/news-details.php . I need the div variable in the news.php file for the user ie news.php?div=user .

EDIT: Now here is the Htaccess code. This causes a problem for the root news page. Options

 +FollowSymLinks RewriteEngine on # For Accessing News Details Page for root http://www.domain.com/news/news-details.php RewriteCond %{HTTP_HOST} ^www.domain\.com [NC] RewriteRule ^news/news-details.php$ news.php [QSA,NC,L] # For Accessing News Details Page http://user.domain.com/news/news-details.php RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com [NC] RewriteCond %{HTTP_HOST) !^www\. RewriteRule ^news/news-details.php$ news.php?div=%1 [QSA,NC,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 user.domain.com should go to domain.com/divisions.php?division=user RewriteCond %{HTTP_HOST} !^www\.domain\.com$ RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ RewriteRule ^$ /divisions.php?division=%1 [L] 

AGAIN IMAGES:

These two rules conflict here.

 # For www.domain.com it should go to my-index.php page # RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC] RewriteRule ^(.*)$ my-index.php [NC,L] # For Page URL http://www.domain.com/news/news-details.php # RewriteCond %{REQUEST_URI} ^/news/news\-details\.php [NC] RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC] RewriteRule ^(.*)$ my-news.php [NC,QSA,L] 
+6
source share
1 answer

Try the following:

 RewriteCond %{REQUEST_URI} ^/news/news\-details.php$ RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.domain\.com$ [NC] RewriteCond %1 !^www$ [NC] RewriteRule ^(.*)$ news.php?div=%1 [NC,QSA,L] RewriteCond %{REQUEST_URI} ^/news/news\-details\.php [NC] RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC] RewriteRule ^(.*)$ news.php [NC,QSA,L] RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php [NC,QSA,L] RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.domain\.com$ [NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ divisions.php?division=%1 [NC,QSA,L] 
+11
source

Source: https://habr.com/ru/post/897741/


All Articles