Forum Moderators: phranque
1. for subdomain rewriting: #*$!.domain.com is internally redirected to file.php?item=#*$!
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([^.]+).domain.com$ [NC]
RewriteRule ^$ /file.php?item=%2 [QSA,nc] 2. ordinary rewriting:
RewriteRule ^([A-Za-z0-9_)(:!-',]+)/?$ file.php?item=$1 [L] What i need to achieve is writing a third rule that will combine these two rules without being in conflict with them. Namely, below (or above) this lines i need to have something like that:
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com/([A-Za-z0-9_)(:!-',]+)$ [NC] RewriteRule ^$ /anotherfile.php?item1=%2&item2=$1 [QSA,nc] so that [#*$!.domain.com...] will be redirected to anotherfile.php?item1=#*$!&item2=yyy
any ideas what is the correct way of it?
Hyphens within [alternate character groups] and literal periods *not* within [alternate character groups] must be escaped in the regular-expressions patterns as shown.
Try this new rule ahead of your current rules, and fix the problems in your current rules as shown:
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.example\.com [NC]
RewriteRule ^([a-z0-9_)(:!',\-]+)/?$ anotherfile.php?item1=%2&item2=$1 [NC,QSA,L]
#
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.example\.com [NC]
RewriteRule ^$ file.php?item=%2 [QSA,L]
#
RewriteRule ^([a-z0-9_)(:!',\-]+)/?$ file.php?item=$1 [NC,QSA,L]
If it is not possible to handle this in your script(s), then the code above should be modified to reject casing errors and trailing-slash errors, and additional rules should be added ahead of them to externally redirect all casing and trailing-slash variants to the correct canonical URL.
All additions, deletions, and modifications in the code above were intentional, and most cause important changes/improvements in the function of the code.
Jim