子域redirect使用htaccess

我正在开发一个需要重写URL的项目

https://orange.url.com

https://www.url.com/?s=orange

我需要关于如何驱动htaccess来处理这个任务的帮助。 PS:请不要在我的htaccess中为我处理一些重写。

RewriteEngine On RewriteBase / # To externally redirect /dir/foo.php to /dir/foo RewriteCond %{THE_REQUEST} ^[AZ]{3,}\s([^.]+)\.php [NC] RewriteRule ^ %1/ [R,L] # add a trailing slash RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteCond %{REQUEST_URI} !/$ RewriteRule . %{REQUEST_URI}/ [R,L] # To internally forward /dir/foo to /dir/foo.php RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*?)/?$ $1.php [L] 

你可以把这个代码放在你的htaccess(必须在你的根目录下)

 Options -MultiViews RewriteEngine On RewriteBase / # To internally forward http://xxx.domain.com to http://www.domain.com/?s=xxx RewriteCond %{HTTP_HOST} ^((?!www\.).+?)\.example\.com$ [NC] RewriteRule ^$ index.php?s=%1 [L] # To internally forward http://xxx.domain.com/yyy/ to http://www.domain.com/?s=xxx&c=yyy RewriteCond %{HTTP_HOST} ^((?!www\.).+?)\.example\.com$ [NC] RewriteRule ^([^/]+)/$ index.php?s=%1&c=$1 [L] # To internally forward http://xxx.domain.com/yyy/zzz/ to http://www.domain.com/?s=xxx&c=yyy&g=zzz RewriteCond %{HTTP_HOST} ^((?!www\.).+?)\.example\.com$ [NC] RewriteRule ^([^/]+)/([^/]+)/$ index.php?s=%1&c=$1&g=$2 [L] # To externally redirect /dir/foo.php to /dir/foo/ RewriteCond %{THE_REQUEST} \s/(.+?)\.php [NC] RewriteRule ^ %1/ [R,L] # add a trailing slash RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !/$ RewriteRule ^(.*)$ $1/ [R,L] # To internally forward /dir/foo/ to /dir/foo.php RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}/$1\.php -f RewriteRule ^(.+?)/$ $1.php [L]