簡體   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