如何使用.htaccess删除URL的一部分并每次都重定向到特定文件

时间:2019-03-27 11:14:29

标签: php .htaccess webserver

我正在同一台计算机上设置两个不同的Web应用程序,并且我想以这种方式更改.htaccess文件,而该文件可以工作而无需在服务器中拥有新域。更确切地说,我想删除部分网址。

/var/www/html/目录中,我有两个不同的Web应用程序

/var/www/html/ │---webapp1/ │ │---public/ │ │ │---index.php │ │---.htaccess │---webapp2/ │ │---public/ │ │ │---index.php │ │---.htaccess

index.php检查URL

$url = explode('/', trim($request));
$this->controller = isset($url[0]) ? $url[0].'Controller':'loginController';

因此,如果我在根文件夹中只有一个Web应用程序,它将可以正常工作。但是现在我的URL是domain.com/webapp1/public/,我想从URL中删除/webapp1/public/部分。

两个网络应用程序中我的.htaacess文件看起来像:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ index.php [QSA,L]

如果我将000-default.conf更改为:

DocumentRoot "/var/www/html/webapp1/public/"
<Directory "/var/www/html//webapp1/public/">
</Directory>

它适用于webapp1

我尝试将webapp1的.htaccess更改为:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^.*$ /webapp1/public/index.php [QSA,L]

但它不起作用。

任何帮助将不胜感激。

0 个答案:

没有答案