【发布时间】:2017-06-10 08:11:12
【问题描述】:
我有一个正在更新的网站。我已将所有库、资源、配置等复制到文件夹 newsite。由于我没有实现任何 url 重写根旧站点,我想在更新站点中实现它。因此,我在 newsite 文件夹中添加了 .htaccess 文件。下面是文件夹结构。
root/
|-- config/
|-- libraries/
|-- resources/
|-- newsite/
| |-- config/
| |-- libraries/
| |-- resources/
| |-- index.php
| |-- .htaccess
|-- index.php
|-- login.php
|-- services.php
|-- contact.php
我希望旧站点以现在的方式运行,但我想实现对新站点的 url 重写。
基本上,新网站的网址是:
https://exmple.com/newsite/
https://exmple.com/newsite/services
https://exmple.com/newsite/login
https://exmple.com/newsite/contact
或任何其他网址。下面是我写的重写规则。
RewriteEngine On
RewriteBase /newsite
RewriteCond %{REQUEST_URI} ^/newsite
RewriteRule ^newsite/(.+)$ /newsite/index.php?page_name=$1 [QSA,L]
【问题讨论】:
-
/newsite/ 对于 root/newsite/.htaccess 被丢弃,所以这个规则只对 root/.htaccess 有意义。同时删除多余的
RewriteBase。
标签: php apache .htaccess mod-rewrite