.htaccess - 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]
解决方案
推荐阅读
- mongodb - 如何将多个文档从单个集合转换为包含一个数组的单个文档
- ruby-on-rails - ActiveRecord::RecordNotFound(找不到没有 ID 的订阅):
- razor - 为什么html输入时间控件绑定到blazor中的属性时会失去焦点?
- google-cloud-firestore - 有没有办法清空 Firebase Cloud Functions 中的缓存变量?
- powershell - 如何通过命令行或 Power Shell 在 Window 10 上启用虚拟化?
- json - 使用 Axios 和 Vue 从 JSON API 获取远程数据
- java - Order类的电子商务底层设计
- html -
与 flex-direction: column 结合使用时在 Firefox 中被忽略 - python - 未知字段类型:尝试打开 DBF 数据库时为 64
- swagger - ASP.Net Core 3.1 Swagger Page Loads via HTTPS but Try It Now uses HTTP and Browser Fails Request