dpnzf48660 2014-01-01 19:32
浏览 58
已采纳

mod_rewrite隐藏.php扩展名并删除其他标题

I would like to hide php extension in url and in the responses of my Apache

I tried it with the following tipycal configuration:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L,QSA]

DirectoryIndex index.php index.html

DocumentRoot /var/www/mysite
<Directory /var/www/mysite>
    Options -Indexes -MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
...

but I do not understand why Apache adds a set of headers that I think are unnecessary. for example about this url:

http://mysite/page

Edit: disabling Content Negotiation with -MultiViews cause:

# tailf /var/log/apache2/error.log
[Sun Jan 19 16:35:23 2014] [error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[Sun Jan 19 16:35:23 2014] [debug] core.c(3063): [client 127.0.0.1] r->uri = /var/www/index.php
[Sun Jan 19 16:35:23 2014] [debug] core.c(3069): [client 127.0.0.1] redirected from r->uri = /var/www/index.php
...
[Sun Jan 19 16:35:23 2014] [debug] core.c(3069): [client 127.0.0.1] redirected from r->uri = /var/www/index.php
[Sun Jan 19 16:35:23 2014] [debug] core.c(3069): [client 127.0.0.1] redirected from r->uri = /page
[Sun Jan 19 16:35:23 2014] [debug] mod_deflate.c(615): [client 127.0.0.1] Zlib: Compressed 533 to 322 : URL /var/www/index.php


# tailf /var/log/apache2/rewrite.log 
127.0.0.1 - - [19/Jan/2014:18:42:06 +0100] [mysite/sid#7fa89ea62d58][rid#7fa89ed69340/initial] (1) pass through /page
127.0.0.1 - - [19/Jan/2014:18:42:06 +0100] [mysite/sid#7fa89ea62d58][rid#7fa89ed69340/initial] (1) [perdir /var/www/] internal redirect with /var/www/index.php [INTERNAL REDIRECT]
127.0.0.1 - - [19/Jan/2014:18:42:06 +0100] [mysite/sid#7fa89ea62d58][rid#7fa89ed75738/initial/redir#1] (1) pass through /var/www/index.php
127.0.0.1 - - [19/Jan/2014:18:42:06 +0100] [mysite/sid#7fa89ea62d58][rid#7fa89ed75738/initial/redir#1] (1) [perdir /var/www/] internal redirect with /var/www/index.php [INTERNAL REDIRECT]
127.0.0.1 - - [19/Jan/2014:18:42:06 +0100] [mysite/sid#7fa89ea62d58][rid#7fa89ed77ad0/initial/redir#2] (1) pass through /var/www/index.php
...
  • 写回答

3条回答 默认 最新

  • dqxsuig64994 2014-01-22 03:20
    关注
    ...
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^\.]+)$ $1.php [L,QSA]
    
    DocumentRoot /var/www/mysite
    <Directory /var/www/mysite>
    Options -Indexes -MultiViews FollowSymLinks
    ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于将inet引入的相关问题
  • ¥15 关于一个倒计时的操作和显示设计
  • ¥15 提问STK的问题,哪位航天领域的同学会啊
  • ¥15 苹果系统的mac m1芯片的笔记本使用ce修改器使用不了
  • ¥15 单相逆变的电压电流双闭环中进行低通滤波PID算法改进
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 如何卸载arcgis 10.1 data reviewer for desktop
  • ¥15 共享文件夹会话中为什么会有WORKGROUP
  • ¥15 关于#python#的问题:使用ATL02数据解算光子脚点的坐标(操作系统-windows)
  • ¥115 关于#python#的问题:未加密前两个软件都可以打开,加密后只有A软件可打开,B软件可以打开但读取不了数据