首页 > 解决方案 > URL 在使用 .htaccess 进行 URL MASKING 之后显示目录:-> PHP

问题描述

我刚刚更新了我的 .htaccess 以屏蔽 localhost url,但是在屏蔽之后,当我运行 url 时。它向我展示了它不应该的目录结构。我对 url masking 的概念很陌生。

谁可以帮我这个事 。

下面是我的目录结构

http://localhost/CentralizedUI/CentralizedDashboardNew/html/demos/default/index.php

下面是我的 .htaccess 文件

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/?CentralizedUI/?$ [NC]
RewriteRule ^.+$ /CentralizedUI/CentralizedDashboardNew/html/demos/default/index.php/

RewriteCond %{REQUEST_URI} ^/?/CentralizedUI/CentralizedDashboardNew/html/demos/default/index.php
RewriteCond %{QUERY_STRING} !^
RewriteRule ^.+$ CentralizedUI/

当我运行它显示的网址时

结构

我想要的是删除 URL 中文件的目录名称和扩展名。

我更新了代码:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(?:CentralizedUI/CentralizedDashboardNew/html/demos/default/)?(.*)$ /CentralizedUI/$1 [NC,L]

但无法删除扩展名 .php

**基于 Ravinder 回答的新编辑**

RewriteEngine ON
RewriteRule ^CentralizedUI/CentralizedDashboardNew/html/demos/default/([^.]*)\.php/?$ /CentralizedUI/$1? [R=301,NC,L]
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^CentralizedUI/(.*)/?$ CentralizedUI/CentralizedDashboardNew/html/demos/default/$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ CentralizedUI/CentralizedDashboardNew/html/demos/default/index.php [L]

标签: .htaccesslocalhost

解决方案


推荐阅读