Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php .htaccess文件仅在子文件夹中,而不是根文件夹中_Php_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php .htaccess文件仅在子文件夹中,而不是根文件夹中

Php .htaccess文件仅在子文件夹中,而不是根文件夹中,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我有一个网站,我目前正在更新。我已将所有库、资源、配置等复制到一个文件夹newsite。由于我还没有实现对旧站点根目录的url重写,所以我想在更新站点中实现它。因此,我在newsite文件夹中添加了.htaccess文件。下面是文件夹结构 root/ |-- config/ |-- libraries/ |-- resources/ |-- newsite/ | |-- config/ | |-- libraries/ | |-- resources/ | |--

我有一个网站,我目前正在更新。我已将所有库、资源、配置等复制到一个文件夹newsite。由于我还没有实现对旧站点根目录的url重写,所以我想在更新站点中实现它。因此,我在newsite文件夹中添加了.htaccess文件。下面是文件夹结构

root/
|-- config/
|-- libraries/
|-- resources/
|-- newsite/
|     |-- config/
|     |-- libraries/
|     |-- resources/
|     |-- index.php
|     |-- .htaccess
|-- index.php
|-- login.php
|-- services.php
|-- contact.php
我希望旧站点能够像现在这样运行,但我希望实现对新站点的url重写

基本上,新站点的url为:

https://exmple.com/newsite/
https://exmple.com/newsite/services
https://exmple.com/newsite/login
https://exmple.com/newsite/contact
或任何其他url。下面是我写的重写规则

RewriteEngine On
RewriteBase /newsite
RewriteCond %{REQUEST_URI} ^/newsite
RewriteRule ^newsite/(.+)$ /newsite/index.php?page_name=$1 [QSA,L]

如果我理解正确,下面的方法应该可以

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,R=301]
这将把所有不以/public/或/root/开头的请求重定向到以/public/或/root/开头的URL


希望对您有所帮助。

/newsite/对于root/newsite/.htaccess被丢弃,因此此规则仅适用于root/.htaccess。同时删除冗余的
RewriteBase
。这不起作用。在您的情况下,您将忽略该文件夹。但是如果文件夹在url中,那么它应该重写url。创建一个路由页面,所有url在添加后都是路由。根文件夹中的htaccess文件,如`root/.htaccess`