php - htaccess mod_rewrite 转换 url
问题描述
我有一个使用目录结构的 php 项目,我想创建漂亮的 url。基本上我想删除每个文件的“.php”扩展名并删除本地主机和文件名之间的路径内容。
例子:
转换这个 =>localhost/myproject/views/pages/login/login.php
进入这个=>localhost/myproject/login
我知道我必须配置 .htaccess mod_rewrite 但我不知道如何诚实。
解决方案
Try and add this to your .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
It should basically remove all the .php extensions from being showed.
推荐阅读
- wireshark - OrangePi(Lubuntu)下的监控模式下未完全列出Wireshark wifi流量
- java - 错误 - 无法确定数据库类型 NONE 的嵌入式数据库驱动程序类
- python - 如何通过子进程运行非结束进程并分别收集 STDOUT 和 STDERR
- php - symfony3中的array_udiff - 找不到函数
- python - 在熊猫多索引中填充“空白”值以访问较低级别的索引
- c++ - 在共享库中查找引用未定义符号的源文件
- python - Python:基于多个条件聚合和平均行
- laravel-5 - Laravel Vue.js 与 CKeditor 4 和 CKFinder3(文件管理器)的集成
- python - 放大图像(可能像素化但不模糊)
- docker - 有没有办法让 docker 管道文件确定它运行的子节点的映像?