指向项目的网址:http://localhost/project5/public/index.php
我想重写网址并使其看起来像http://localhost/project5/index.php
目录结构
project5
│
├───includes
├───public
│ │───css
│ │───js
│ │───img
│ │───index.php
│ └───residential-for-sale.php
├───logs
.htaccess代码我用来隐藏.php扩展名并将“public”作为我的工作目录并从网址中删除“public”:
RewriteEngine On
Options +FollowSymLinks -MultiViews -Indexes
DirectoryIndex index.php
# hide .php Extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
# to hide public directory
RewriteRule ^project5/((?!public/).*)$ project5/public/$1 [L]
当我尝试访问http://localhost/project5/index.php
时,它会抛出错误404:找不到页面
答案 0 :(得分:0)
试试这段代码:
RewriteEngine On
Options +FollowSymLinks -MultiViews -Indexes
DirectoryIndex index.php
# hide .php Extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
# to hide public directory
RewriteRule ^project5/((?!public/).*)$ project5/public/$1 [L]