繁体   English   中英

htaccess子域和目录重定向

[英]htaccess subdomain and directory redirect

我需要将带有尾随信息的通配符子域选项重定向到2个单独的php变量中。

例如。 http://company.domain.com/xyz

需要去

http://domain.com/redirect.php?url=xyz&user=company

我正在使用短网址重定向器,并且当前正在使用以下htaccess命令:

RewriteCond %{REQUEST_URI} ^(.+)\!$
RewriteRule ^(.*) stats.php?url=$1 [L]
RewriteCond %{REQUEST_URI} ^(.+)\~s$
RewriteRule ^(.*) stats.php?url=$1 [L]
RewriteCond %{REQUEST_URI} ^(.+)\~q$
RewriteRule ^(.*) generate_qr.php?url=$1 [L]
RewriteCond %{REQUEST_URI} ^(.+)\~p$
RewriteRule ^(.*) preview_url.php?url=$1 [L]
RewriteCond %{REQUEST_URI} !^(.+)\.html$
RewriteCond %{REQUEST_URI} !^(.+)\.htm$
RewriteCond %{REQUEST_URI} !^(.+)\.php$
RewriteCond %{REQUEST_URI} !^(.+)\.js$
RewriteCond %{REQUEST_URI} !^(.+)\.css$
RewriteCond %{REQUEST_URI} !^(.+)\.jpg$
RewriteCond %{REQUEST_URI} !^(.+)\.png$
RewriteCond %{REQUEST_URI} !^(.+)\.gif$
RewriteCond %{REQUEST_URI} !^(.+)\.swf$
RewriteCond %{REQUEST_URI} !^(.+)\.xml$
RewriteCond %{REQUEST_URI} !^(.+)\.ico$
RewriteCond %{REQUEST_URI} !^(.+)\.txt$
RewriteCond %{REQUEST_URI} !^index\.html$
RewriteCond %{REQUEST_URI} !^index\.php$
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) url_redirector.php?url=$1 [L]
RewriteRule ^(.*).html$ $1.php [L]

所以我需要添加一些东西

RewriteCond %{HTTP_HOST} ^([^/.]+)\.domain\.com/$ 
RewriteRule ^(.*) url_redirector.php?url=$1&user=%1 [L]

其中“用户”是子域的值,同时保持重定向器的条件重写。 怎么做?

将此规则作为您的第一条规则

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$ [NC]
RewriteRule ^(.*)$ http:domain.com//redirect.php?url=$1&user=%1 [L]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM