简体   繁体   中英

htaccess subdomain and directory redirect

I need to redirect a wildcard subdomain option with the trailing information into 2 separate php variables.

So for example. http://company.domain.com/xyz

Needs to go to

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

I am using a short url redirector, and they are currently using the following htaccess commands:

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]

So I need to add Something like

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

Where the "user" is the value of the subdomain, while maintaining the conditional rewrites of the redirector. How would this be done?

Place this rule as your very first rule :

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$ [NC]
RewriteRule ^(.*)$ http:domain.com//redirect.php?url=$1&user=%1 [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.

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