.htaccess 重写 - 屏蔽动态 .php 扩展
.htaccess Rewrite - Masking Dynamic .php extensions
我知道之前有人问过关于 .htaccess 的类似问题,但在阅读问题、答案和评论数小时后,以及无数小时阅读 .htaccess 文档甚至尝试 .htaccess 生成器之后。 .并通过尝试示例搞乱我的网站访问...我来寻求那些比我更聪明的人的指导。
我正在使用以下 .htaccess 文件从浏览器中向用户显示的 URLS 中删除 .php 扩展名
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ .php
This works perfectly
www.example.com/users/player.php?id=1 is being correctly shown as
www.example.com/users/player?id=1
我现在正在努力 write/find/understand 允许我重写完整扩展的示例
I want to show
www.example.com/users/player.php?id=1
as
www.example.com/users/1
totally removing the player.php?id= part of the dynamic URL
提前感谢您的任何 help/guidance。
对于任何想做我想做的事情的人,我已经找到了解决方案。
问题:
这将允许您在外部将“edit.php?id=1”屏蔽为“edit/id/1”,并可互换使用 URL。
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/([^/]+)/edit\.php\?id=([^\s&]+) [NC]
RewriteRule ^ %1/edit/id/%2? [R=302,L,NE]
RewriteRule ^([^/]+)/edit/id/([^/.]+)$ /edit.php?id= [NC,L,QSA]
祝你好运!
我知道之前有人问过关于 .htaccess 的类似问题,但在阅读问题、答案和评论数小时后,以及无数小时阅读 .htaccess 文档甚至尝试 .htaccess 生成器之后。 .并通过尝试示例搞乱我的网站访问...我来寻求那些比我更聪明的人的指导。
我正在使用以下 .htaccess 文件从浏览器中向用户显示的 URLS 中删除 .php 扩展名
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ .php
This works perfectly
www.example.com/users/player.php?id=1 is being correctly shown as www.example.com/users/player?id=1
我现在正在努力 write/find/understand 允许我重写完整扩展的示例
I want to show
www.example.com/users/player.php?id=1
as
www.example.com/users/1
totally removing the player.php?id= part of the dynamic URL
提前感谢您的任何 help/guidance。
对于任何想做我想做的事情的人,我已经找到了解决方案。
问题:
这将允许您在外部将“edit.php?id=1”屏蔽为“edit/id/1”,并可互换使用 URL。
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/([^/]+)/edit\.php\?id=([^\s&]+) [NC]
RewriteRule ^ %1/edit/id/%2? [R=302,L,NE]
RewriteRule ^([^/]+)/edit/id/([^/.]+)$ /edit.php?id= [NC,L,QSA]
祝你好运!