.htaccess重定向到子域并隐藏在uri中?

时间:2019-03-19 18:11:55

标签: php .htaccess

我要重定向以下请求:

http://example.com/page1.php (<-non-existent url to file)

http://example.com/content/sites/page1.php (<-real path to file in folder structure)

同时仍继续显示

http://example.com/page1.php

在浏览器中,并使用位于根文件夹中的.htaccess文件。

这有可能吗?在此先感谢:)

1 个答案:

答案 0 :(得分:0)

根据您的评论,以下规则是您所做的:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.*)$ $1.php

他们会检查请求是否不是目录,然后检查请求是否被接受.php然后重写它,根本不需要它。

通常请尝试以下操作:

RewriteEngine On 
RewriteRule ^([^\/]+\.php)$   content/sites/$1 [L]

如果只希望page1.php这样做,请执行以下操作:

RewriteEngine On 
RewriteRule ^(page1\.php)$  content/sites/$1 [L]

注意:清除浏览器缓存,然后进行测试

相关问题