Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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
使用.htaccess从/settings/重定向到settings.php_Php_.htaccess - Fatal编程技术网

使用.htaccess从/settings/重定向到settings.php

使用.htaccess从/settings/重定向到settings.php,php,.htaccess,Php,.htaccess,我想使用.htacess文件从localhost/myproject/setting/重定向到localhost/myproject/settings.php 我使用了以下规则: RewriteRule ^setting/$ settings.php [L] 但是,它首先将我带到localhost/myproject/setting/,然后运行settings.php文件。我不要这个。[我的根目录中没有名为“setting”的文件夹!] 如何解决我的问题?如果我理解正确,您希望从任何开始重定

我想使用
.htacess
文件从localhost/myproject/setting/重定向到localhost/myproject/settings.php

我使用了以下规则:

RewriteRule ^setting/$  settings.php [L]
但是,它首先将我带到localhost/myproject/setting/,然后运行settings.php文件。我不要这个。[我的根目录中没有名为“setting”的文件夹!]


如何解决我的问题?

如果我理解正确,您希望从任何开始重定向
localhost/myproject/setting/
localhost/myproject/setting/anything.php
localhost/myproject/settings.php

RewriteEngine on
RewriteBase /
RewriteRule  "^/setting/(.*)$" "settings.php" [L]
如果您想将GET变量发送到
/seting/
以传递到
settings.php
,请使用以下命令

RewriteRule  "^/setting/(.*)$" "settings.php$1" [L, PT]

问题是,当您的规则匹配时,它会在
/setting/
文件夹中匹配。然后,它尝试在内部将其重写为当前文件夹中的
settings.php
(因为您使用的是相对路径)。解决方案:使用
RewriteBase
而不是使用相对/绝对路径

下面是您的
/myproject/.htaccess
文件的外观

Options -MultiViews

RewriteEngine On
RewriteBase /myproject/

# RewriteBase path (/myproject/) is always added in front of relative path -> /myproject/settings.php
RewriteRule ^setting/$  settings.php [L]

你第一次打电话是什么意思?您的浏览器必须首先调用/settings/,因为它需要有关重定向的信息。非常感谢。另一个问题对我来说仍然存在。使用localhost/myproject/settings.php时,所有css、图像和AJAX代码都能正确运行。但是当使用localhost/myproject/setting/时,经过htacess重写后,图像不会显示,ajax代码也不会工作。还有一个简单的解决方法吗?打开一个新问题,再详细一点,发布一点不起作用的代码,等等。我答应帮忙。