我如何使用的.htaccess隐藏的.php URL扩展? [英] How can I use .htaccess to hide .php URL extensions?

查看:309
本文介绍了我如何使用的.htaccess隐藏的.php URL扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的东西,把我的的.htaccess 文件,将隐藏的.php 文件扩展我的PHP文件,因此要www.example.com/dir/somepage~~V会告诉他们www.example.com/dir/somepage.php。

对此有任何可行的解决方案?我的网站使用HTTPS,如果在所有重要的。

这是我的.htaccess的时刻:

  RewriteEngine叙述上

的RewriteCond%{} SERVER_PORT 80
重写规则^(。*)$ https://www.example.com/$1 [R,L]

ErrorDocument的404 /error/404.php

的RewriteCond%{} REQUEST_FILENAME -f .PHP
的RewriteCond%{REQUEST_URI}!/ $
重写规则(。*)$ 1 \ .PHP [L]
 

解决方案

使用这种code在你的.htaccess下DOCUMENT_ROOT:

 选项+了FollowSymLinks -MultiViews
#开启mod_rewrite的上
RewriteEngine叙述上
的RewriteBase /

#要外部重定向/dir/foo.php到/ DIR /富
的RewriteCond%{THE_REQUEST} ^ [AZ] {3,} \ S([^。] +)\。PHP [NC]
重写规则^%1 [R,L,NC]

##在内部重定向/ DIR /富到/dir/foo.php
的RewriteCond%{} REQUEST_FILENAME -f .PHP [NC]
重写规则^%{REQUEST_URI}的.php [L]
 

I want something to put in my .htaccess file that will hide the .php file extension for my php files, so going to www.example.com/dir/somepage would show them www.example.com/dir/somepage.php.

Is there any working solution for this? My site uses HTTPS, if that matters at all.

This is my .htaccess at the moment:

RewriteEngine On

RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

ErrorDocument 404 /error/404.php

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]

解决方案

Use this code in your .htaccess under DOCUMENT_ROOT:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f [NC]
RewriteRule ^ %{REQUEST_URI}.php [L]

这篇关于我如何使用的.htaccess隐藏的.php URL扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆