简体   繁体   English

如何使用.htaccess和Remove .php扩展名来装饰URL

[英]How To Decorate URL using .htaccess and Remove .php extension

This is Current URL and i want to remove "/public/index.php" from the URL then How to write .htaccess 这是当前的URL,我想从URL中删除“/public/index.php”然后如何写.htaccess

Blockquote http://localhost/Fresh/public/index.php Blockquote http://localhost/Fresh/public/index.php

.htaccess 的.htaccess

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...


RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^ index.php [L]

This is my Directory Structure 这是我的目录结构 在此输入图像描述

How to rewrite .htaccess to remove subdirectory and Decorate the URL. 如何重写.htaccess来删除子目录并装饰URL。

try this 尝试这个

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

OR 要么

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

Hope it will help you. 希望它会对你有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM