从 URL 中删除 .php [英] Remove .php from URL
问题描述
Ubuntu 14.04LTS 32 位
Ubuntu 14.04LTS 32bit
灯
我知道这是一个老问题,但是..
I know it's an old question but..
我需要它从可见 url 找到它的任何地方删除 .php.它需要使用/showthread.php?id=XX --->/showthread?id=XX
I need it to remove .php anywhere it finds it from the visible url. It needs to work with /showthread.php?id=XX ---> /showthread?id=XX
我什至无法让它与 /page.php
--> /page
一起工作.我试过这些:
I can't even get it to work with /page.php
--> /page
.
I've tried these:
如何使用 Apache 隐藏 .html 扩展名mod_rewrite
它什么都不做.虽然其他 .htaccess
代码工作正常..
It just does nothing at all.
While other .htaccess
code works fine..
虽然
<?php
phpinfo();
列出加载模块中的 mod_rewrite
Lists mod_rewrite in Loaded Modules
和
<?php
if(!function_exists('apache_get_modules') ){ phpinfo(); exit; }
$res = 'Module Unavailable';
if(in_array('mod_rewrite',apache_get_modules()))
$res = 'Module Available';
?>
<html>
<head>
<body>
<p><?php echo apache_get_version(),"</p><p>mod_rewrite $res"; ?></p>
</body>
</html>
返回模块可用
尝试了很多东西
# Apache Rewrite Rules
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Add trailing slash to url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ $1/ [R=301,L]
# Remove .php-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php
# End of Apache Rewrite Rules
</IfModule>
#
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
#
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
即使这样也没有任何影响:
Not even this has any effect whatsoever:
RewriteRule ^page$ page.php [L]
sudo service apache2 restart
不会改变任何东西.
服务器重启没有任何改变.
Server reboot changes nothing.
我尝试清除里面的其他代码,没有做任何改变.
I tried clearing other code inside, did not make any change.
我清除了浏览器缓存 100 次
I cleared my browser cache 100 times
我开始认为它只是讨厌我.这可能是什么原因造成的??
I'm starting to think that it just hates me. What could possible be causing this??
推荐答案
希望有所帮助.
它对我有用.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# For LocalHost !.php
RewriteCond %{HTTP_HOST} !=localhost
RewriteCond %{HTTP_HOST} !=127.0.0.1
RewriteCond %{REMOTE_ADDR} !=127.0.0.1
RewriteCond %{REMOTE_ADDR} !=::1
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=302,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
这篇关于从 URL 中删除 .php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!