Mod_rewrite with subdomain and URL pattern

I want to use the subdomain as a get variable with mod_rewrite AND use some parameter:

eg /page/language/site/counterindex.php?o=operator&lg=language&s=arg1&c=arg2

How to do this with mod_rewrite?

RewriteEngine On  

RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} ^([a-zA-Z]{3,6})\.example\.com  
RewriteRule ^index/([a-z]{2})/([0-9]{1,2})/([0-9]{1,2})$  http://www.example.com/index.php?o=%1&lg=%2&site=%3&counter=%4 [NC,L] # for index.php
RewriteRule ^export/([a-z]{2})/([0-9]{1,2})/([0-9]{1,2})$  http://www.example.com/export.php?o=%1&lg=%2&site=%3&counter=%4 [NC,L] # for export.php

Any idea?

Thanks in advance

+3
source share
1 answer

A RewriteCondbelongs only to the next one RewriteRule. Therefore, in your case, both directives RewriteCondapply only to the first directive RewriteRule, and the second RewriteRulehas no related directives RewriteCond.

You can fix this in your example by combining the two RewriteRules:

RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([a-zA-Z]{3,6})\.example\.com$
RewriteRule ^(index|export)/([a-z]{2})/([0-9]{1,2})/([0-9]{1,2})$ http://www.example.com/$1.php?o=%1&lg=$2&site=$3&counter=$4 [NC,L]

$n %n, $n n- RewriteRule, %n n- RewriteCond.

0

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


All Articles