I am going through a strange behaviour of .htaccess.
I am writing a rule of .htaccess to convert the below url :
I want to convert the following URL (where site
is variable.)
www.xyz.com/domain/site
to
site.xyz.com/
Note that /site
is generated at runtime. (Created by user)
But my rule is not working.
MY CODE
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !www.xyz.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).xyz.com [NC]
RewriteRule (.*) nono.html?sm=%2 [NC,QSA]
Your current rule appears to "sort of" do the opposite of what you are asking in the question, but with an extra twist. ie. a URL for the form site.xyz.com/something
would be internally rewritten to site.xyz.com/nono.html?sm=site
. (?)
To redirect www.xyz.com/domain/site
to site.xyz.com/
, as you've stated, then you could do something like:
RewriteCond %{HTTP_HOST} ^www\.(xyz\.com)$ [NC]
RewriteRule ^domain/([^/]+)$ http://$1.%1/ [R=302,L]
Change the 302
(temporary) redirect to 301
(permanent) when you are sure this is working OK. Or test with browser caching disabled. ( 301
redirects are otherwise cached by the browser, so can make testing problematic.)
I got your issue.
your re-write rule is just opposite..
use this for your exact problem
and it will work
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^(www\.)?xyz.com/domain/(.+)$(.*)
RewriteRule (.*) https://$1.xyz.com/ [L]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.