Php 在URL中隐藏目录名
我的网站目录是:Php 在URL中隐藏目录名,php,apache,.htaccess,Php,Apache,.htaccess,我的网站目录是: localhost/ includes/ includes/initialize.php includes/user.php includes/session.php includes/database.php public/ public/bootstrap/ public/css/ public/js/ public/dashb
localhost/
includes/
includes/initialize.php
includes/user.php
includes/session.php
includes/database.php
public/
public/bootstrap/
public/css/
public/js/
public/dashboard/index.php
public/index.php
.htaccess(first htaccess file)
{
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/$1 [QSA,L]
</IfModule>
}
localhost/
包括/
includes/initialize.php
包括/user.php
包括/session.php
包括/database.php
公开的/
公共/引导/
公共/css/
公共事务/js/
public/dashboard/index.php
public/index.php
.htaccess(第一个htaccess文件)
{
重新启动发动机
重写cond%{REQUEST_FILENAME}!-f
重写规则^(.*)$public/$1[QSA,L]
}
例如,我希望我的url更整洁
当我键入以下内容时:http://localhost
我知道它会转到http://localhost/public/
但是URL仍然是http://localhost
但问题是当我输入http://localhost/dashboard
不幸的是,URL将是http://localhost/public/dashboard/
在我的浏览器上
我不想看到公开这个词
我想我应该在公共目录下有另一个htaccess文件,但我不知道适合它的代码。在您的
文档\u ROOT/中尝试此代码。htaccess
文件:
DirectoryIndex index.html index.php
RewriteEngine On
RewriteRule !^public/ /public%{REQUEST_URI} [NC,L]
你能影响你的服务器配置吗?你应该配置你的服务器,并将webroot定义为你的
公用文件夹。我正在XAMPP上尝试我的代码,我想通过使用.htaccess来解决这个问题。你能显示你的.htaccess文件内容吗?我已经在问题的底部写了。你还有仪表板/.htaccess
?或者dashboard/index.php
使用一些代码更改URL?不,我没有,我的dashboard/index.php没有任何特殊功能。我唯一能说的是在Firebug中运行您的请求,看看您在Net选项卡中得到了什么。您还可以尝试使用其他浏览器来避免301缓存问题。