问题
I'm using the following rewrite on my dev environment (Apache 2) and it works fine, I uploaded to my live environment (LiteSpeed) and it no longer works :(
Any ideas why given the following?
I'm using the "P" directive "mod_proxy" which my host doesn't support. How can I get around this?
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule ^(.*)$ http://example.com/folder/%1/$1 [QSA,NC,P]
# Removes index.php
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
回答1:
I took a different approach to this problem. Apparently the mod_proxy method is inefficient so I solved it in PHP using some simple code to determine the subdomain and apply a conditional to check that $subdomain is not an empty string.
$url_parts = explode('.', str_replace('.example.com', '', $_SERVER['HTTP_HOST']));
$subdomain = ($url_parts[0] !== '') ? $url_parts[0] : '';
I'm just redirecting to the correct page once I know that there is a subdomain.
来源:https://stackoverflow.com/questions/12220181/htaccess-apache-to-litespeed