我如何使用的.htaccess隐藏的.php URL扩展?

编程入门 行业动态 更新时间:2024-10-24 08:20:12
本文介绍了我如何使用的.htaccess隐藏的.php URL扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

这是我的.htaccess的时刻:

RewriteEngine叙述上 的RewriteCond%{} SERVER_PORT 80 重写规则^(。*)$ www.example/$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/dir/somepage would show them www.example/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 ^(.*)$ www.example/$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扩展?

本文发布于:2023-11-01 17:49:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549998.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   htaccess   URL   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!