使用.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代码也不会工作。还有一个简单的解决方法吗?打开一个新问题,再详细一点,发布一点不起作用的代码,等等。我答应帮忙。