从URL删除的.phpURL、php

2023-09-02 11:41:23 作者:时光我恨你

Ubuntu的14.04LTS 32位

Ubuntu 14.04LTS 32bit

LAMP

我知道这是一个老问题,但..

I know it's an old question but..

我需要它删除的.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 工作 - > /页。 我已经尝试了这些:

I can't even get it to work with /page.php --> /page. I've tried these:

删除扩展名为.php用的.htaccess

How隐藏.html扩展与Apache的mod_rewrite

从URL中使用的htaccess 删除的.php

如何停止的.htaccess环

这少了点什么都没有。 而其他的.htaccess code正常工作。

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]

须藤服务的Apache2重启不会改变任何东西。

sudo service apache2 restart does not change anything.

服务器重启没有改变什么。

Server reboot changes nothing.

我试过内部结算等code,没有做出任何改变。

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??

推荐答案

也许这可能是一个重复的,但看看这个:

Maybe this could be a duplicate but take a look at this:

如何从网址的.html

就在该解决方案修改 HMTL PHP

Just in the solution change the hmtl for php