通过隐藏在htaccess的URL文件扩展名 [英] hide file extension in url by htaccess
本文介绍了通过隐藏在htaccess的URL文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想隐藏在浏览器中我的文件扩展名显示出来,如 http://www.example.com/dir/abc.php
应显示为 http://www.example.com/dir/abc
仅
我写了下面的RewriteCond和的.htaccess
选项+的FollowSymLinks
RewriteEngine叙述在
的RewriteBase /
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME -f的.php
重写规则^(。+)$ /$1.php [L,QSA]
但这种code doeesn't似乎我的帮助。
编辑:
这是我的htaccess文件的完整code
选项-Indexes
的ErrorDocument 403 /errors/403.php
ErrorDocument的404 /errors/404.phpRewriteEngine叙述上
的RewriteCond%{HTTP_REFERER} ^ HTTP://(WWW \\)127.0.0.1 [NC]
的RewriteCond%{HTTP_REFERER} ^ HTTP:!?//(WWW \\)127.0.0.1 * $ [NC]
的RewriteCond%{HTTP_REFERER} ^ HTTP://(WWW \\)本地主机[NC]
的RewriteCond%{HTTP_REFERER} ^ HTTP:!?//(WWW \\)本地主机* $ [NC]
重写规则\\。(JS | CSS | JPG | PNG)$ - [F]
RewriteEngine叙述上
重写规则^(。*)\\ [\\ D] {10} \\。(CSS | JS | PNG | JPG)$ $ 1. $ 2 [L]RewriteEngine叙述在#从外部重定向到/dir/file.php / DIR /文件
的RewriteCond%{} THE_REQUEST ^ [A-Z] {3} \\ S / +(。+?)\\ PHP [\\ S?] [NC]
重写规则^ /%1 [R = 301,L,NE]
解决方案
最简单,最简单的方法:
RewriteEngine叙述在的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_FILENAME} \\ PHP -f
重写规则^(。*)$ $ 1.PHP [L]
I want to hide my file extensions in browser to be displayed, like http://www.example.com/dir/abc.php
should be displayed as http://www.example.com/dir/abc
only.
i wrote following rewriteCond and rewrite rule on .htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ /$1.php [L,QSA]
but this code doeesn't seems to helping me.
EDIT: this is complete code of my htaccess file
Options -Indexes
ErrorDocument 403 /errors/403.php
ErrorDocument 404 /errors/404.php
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?127.0.0.1 [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?127.0.0.1.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost.*$ [NC]
RewriteRule \.(js|css|jpg|png)$ - [F]
RewriteEngine on
RewriteRule ^(.*)\.[\d]{10}\.(css|js|png|jpg)$ $1.$2 [L]
RewriteEngine On
# To externally redirect /dir/file.php to /dir/file
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
解决方案
The simplest and easiest way:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
这篇关于通过隐藏在htaccess的URL文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文