0

指向项目的网址:http://localhost/project5/public/index.php

我想重写 url 让它看起来像这样http://localhost/project5/index.php

目录结构

project5
│ 
├───includes
├───public
│   │───css
│   │───js
│   │───img
│   │───index.php
│   └───residential-for-sale.php
├───logs

我用来隐藏 .php 扩展名并将“public”作为我的工作目录并从 url 中删除“public”的 .htaccess 代码:

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:找不到页面

4

1 回答 1

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]
于 2013-09-11T16:45:08.173 回答