用于从 url 中删除部分目录的 Apache 重写规则

Apache rewrite rule for removing part of the directory from the url

我使用 Apache 设置了以下测试站点,并从以下位置提供服务 /htdocs/www/*

https://local.sweetcar.com/www/mycompany/
https://local.sweetcar.com/www/sweetcar/

我想配置一个 apache 重写服务于以下 urls

https://local.mycompany.com/
https://local.sweetcar.com/

因此 www/mycompany/www/sweetcar/ 从 url 中删除而其他一切都被保留

这是我尝试过但没有成功的方法:

.htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

您可以在站点根目录 .htaccess 中使用这些规则:

RewriteEngine On
RewriteBase /

RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteCond %{HTTP_HOST} ^local\.([^.]+)\. [NC]
RewriteRule !^www/ www/%1%{REQUEST_URI} [L,NC]

RewriteRule ^index\.php$ - [L]