.htaccess奇怪的行为

时间:2012-10-30 14:07:17

标签: php apache .htaccess mod-rewrite

我目前正在将Apache2 PHP5生产实例迁移到本地环境。

在.htaccess文件中,我找到了以下重写规则:

RewriteRule ^profile/?$ profile.php

哪个有效。但是,当尝试访问localhost / profile时,我会看到一个空页面,并且这个添加到响应头

Content-Location:profile.class.php

如果我将规则更改为^ profile /?$以外的任何内容,请说^ profil /?$一切正常。

什么可能导致这种奇怪的行为,命名冲突,保留字?

这是来自mod_rewrite

的日志
% tail -f rewrite.log                          
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9c00a0/subreq] (3) [perdir /var/www/] strip per-dir prefix: /var/www/profile.php -> profile.php
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9c00a0/subreq] (3) [perdir /var/www/] applying pattern '^sign-up/?([a-f0-9]+)?/?([a-f0-9]+)?/?$' to uri 'profile.php'
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9c00a0/subreq] (3) [perdir /var/www/] strip per-dir prefix: /var/www/profile.php -> profile.php
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9c00a0/subreq] (3) [perdir /var/www/] applying pattern '^sign-out/?$' to uri 'profile.php'
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9c00a0/subreq] (3) [perdir /var/www/] strip per-dir prefix: /var/www/profile.php -> profile.php
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9c00a0/subreq] (3) [perdir /var/www/] applying pattern '^new-app/?(budget)?/?([A-Za-z0-9-]+)?/?$' to uri 'profile.php'
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9c00a0/subreq] (3) [perdir /var/www/] strip per-dir prefix: /var/www/profile.php -> profile.php
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9c00a0/subreq] (3) [perdir /var/www/] applying pattern '^profile/([a-f0-9]{50})/?([a-f0-9]{50})?/?' to uri 'profile.php'
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9c00a0/subreq] (3) [perdir /var/www/] strip per-dir prefix: /var/www/profile.php -> profile.php
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9c00a0/subreq] (3) [perdir /var/www/] applying pattern '^profile/?([a-z0-9-]+)?/?$' to uri 'profile.php'
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9c00a0/subreq] (3) [perdir /var/www/] strip per-dir prefix: /var/www/profile.php -> profile.php
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] strip per-dir prefix: /var/www/profile.class.php -> profile.class.php
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] applying pattern '^sign-in/?$' to uri 'profile.class.php'
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] strip per-dir prefix: /var/www/profile.class.php -> profile.class.php
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] applying pattern '^features/?$' to uri 'profile.class.php'
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] strip per-dir prefix: /var/www/profile.class.php -> profile.class.php
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] applying pattern '^features/([a-z0-9-]+)/?$' to uri 'profile.class.php'
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] strip per-dir prefix: /var/www/profile.class.php -> profile.class.php
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] applying pattern '^terms/?$' to uri 'profile.class.php'
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] strip per-dir prefix: /var/www/profile.class.php -> profile.class.php
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] applying pattern '^(all|books|business|education|entertainment|finance|games|healthcare-and-fitness|lifestyle|medical|music|navigation|news|photography|productivity|reference|social-networking|sports|travel|utilities|weather)/?$' to uri 'profile.class.php'
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] strip per-dir prefix: /var/www/profile.class.php -> profile.class.php
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] applying pattern '^(books|business|education|entertainment|finance|games|healthcare-and-fitness|lifestyle|medical|music|navigation|news|photography|productivity|reference|social-networking|sports|travel|utilities|weather)/([A-Za-z0-9-]+)/?$' to uri 'profile.class.php'
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] strip per-dir prefix: /var/www/profile.class.php -> profile.class.php
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] applying pattern '^(books|business|education|entertainment|finance|games|healthcare-and-fitness|lifestyle|medical|music|navigation|news|photography|productivity|reference|social-networking|sports|travel|utilities|weather)/([A-Za-z0-9-]+)/invite/?([a-z0-9-]+)?/?$' to uri 'profile.class.php'
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] strip per-dir prefix: /var/www/profile.class.php -> profile.class.php
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] applying pattern '^(books|business|education|entertainment|finance|games|healthcare-and-fitness|lifestyle|medical|music|navigation|news|photography|productivity|reference|social-networking|sports|travel|utilities|weather)/([A-Za-z0-9-]+)/(app-details|testers|test-reports|test-report|start|update|contact-tester)/?(\d+)?/?([a-z0-9-]+)?/?$' to uri 'profile.class.php'
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] strip per-dir prefix: /var/www/profile.class.php -> profile.class.php
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] applying pattern '^forgot-password/?$' to uri 'profile.class.php'
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] strip per-dir prefix: /var/www/profile.class.php -> profile.class.php
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] applying pattern '^connect-with-facebook/?$' to uri 'profile.class.php'
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] strip per-dir prefix: /var/www/profile.class.php -> profile.class.php
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] applying pattern '^account/?(confirm-email|reset-password|send-confirmation-link)/?([A-Za-z0-9]+)?/?([_\.0-9a-zA-Z-%+]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+([a-zA-Z]{2,4}$))?$' to uri 'profile.class.php'
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] strip per-dir prefix: /var/www/profile.class.php -> profile.class.php
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] applying pattern '^public-scripts/?(add-device|propose-projects|generate-mass-payment|edit-device|your-devices|get-app-password|remove-device|beta-test-request|change-project-tester-status|download-udids|download-app|open-report|rate-report|reply|invite-search|invite-user|ignore-invite|uninvite|add-device-over-air|save-device-over-air|send-air-link|search-android-device)/?([A-Za-z0-9]+)?/?([A-Za-z0-9\.]+)?/?$' to uri 'profile.class.php'
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] strip per-dir prefix: /var/www/profile.class.php -> profile.class.php
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] applying pattern '^rss/?$' to uri 'profile.class.php'
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] strip per-dir prefix: /var/www/profile.class.php -> profile.class.php
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (3) [perdir /var/www/] applying pattern '^feed/?$' to uri 'profile.class.php'
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9d20a0/initial] (1) [perdir /var/www/] pass through /var/www/profile.class.php
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9cd0a0/initial] (1) [perdir /var/www/] pass through /var/www/favicon.ico
192.168.0.31 - - [30/Oct/2012:16:18:31 +0100] [192.168.0.40/sid#7f930db80978][rid#7f930d9c12c0/initial/redir#1] (3) [perdir /var/www/] strip per-dir prefix: /var/www/404.php -> 404.php

的.htaccess

RewriteEngine on

RewriteRule ^sign-up/?([a-f0-9]+)?/?([a-f0-9]+)?/?$ sign-up.php?project_token=$1&invite_token=$2
RewriteRule ^sign-out/?$ sign-out.php
RewriteRule ^new-app/?(budget)?/?([A-Za-z0-9-]+)?/?$ new-app.php?stage=$1&app=$2
RewriteRule ^profile/([a-f0-9]{50})/?([a-f0-9]{50})?/? profile-other.php?token=$1&project=$2
RewriteRule ^profile/?([a-z0-9-]+)?/?$ profile.php?profile_menu_cat=$1
RewriteRule ^admin/?([a-z0-9-]+)?/?$ admin.php?profile_menu_cat=$1
RewriteRule ^faq/?(our-application|for-beta-testers|for-developers)?/?$ faq.php?app_cat=$1
RewriteRule ^get/?([A-Za-z0-9-]+)/?([a-z0-9]+)\.?(ipa|plist|apk)?/?$ download.php?url=$1&token=$2&$3
RewriteRule ^contact/?$ contact.php
RewriteRule ^sign-in/?$ sign-in.php
RewriteRule ^features/?$ features.php
RewriteRule ^features/([a-z0-9-]+)/?$ features.php?sub=$1
RewriteRule ^terms/?$ terms.php
RewriteRule ^(all|books|business|education|entertainment|finance|games|healthcare-and-fitness|lifestyle|medical|music|navigation|news|photography|productivity|reference|social-networking|sports|travel|utilities|weather)/?$ browse.php?category=$1

RewriteRule ^(books|business|education|entertainment|finance|games|healthcare-and-fitness|lifestyle|medical|music|navigation|news|photography|productivity|reference|social-networking|sports|travel|utilities|weather)/([A-Za-z0-9-]+)/?$ app.php?category=$1&app=$2&app_cat=$3&extra=$4

RewriteRule ^(books|business|education|entertainment|finance|games|healthcare-and-fitness|lifestyle|medical|music|navigation|news|photography|productivity|reference|social-networking|sports|travel|utilities|weather)/([A-Za-z0-9-]+)/invite/?([a-z0-9-]+)?/?$ invite.php?category=$1&app=$2&app_cat=invite&extra=$4

RewriteRule ^(books|business|education|entertainment|finance|games|healthcare-and-fitness|lifestyle|medical|music|navigation|news|photography|productivity|reference|social-networking|sports|travel|utilities|weather)/([A-Za-z0-9-]+)/(app-details|testers|test-reports|test-report|start|update|contact-tester)/?(\d+)?/?([a-z0-9-]+)?/?$ app.php?category=$1&app=$2&app_cat=$3&extra=$5&version=$4

RewriteRule ^forgot-password/?$ forgot-password.php
RewriteRule ^connect-with-facebook/?$ connect-with-facebook.php
RewriteRule ^account/?(confirm-email|reset-password|send-confirmation-link)/?([A-Za-z0-9]+)?/?([_\.0-9a-zA-Z-%+]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+([a-zA-Z]{2,4}$))?$ account.php?1=$1&2=$2&3=$3
RewriteRule ^public-scripts/?(add-device|propose-projects|generate-mass-payment|edit-device|your-devices|get-app-password|remove-device|beta-test-request|change-project-tester-status|download-udids|download-app|open-report|rate-report|reply|invite-search|invite-user|ignore-invite|uninvite|add-device-over-air|save-device-over-air|send-air-link|search-android-device)/?([A-Za-z0-9]+)?/?([A-Za-z0-9\.]+)?/?$ public-scripts.php?1=$1&2=$2&3=$3
RewriteRule ^rss/?$ rss.php
RewriteRule ^feed/?$ rss.php

ErrorDocument 404 /404.php

1 个答案:

答案 0 :(得分:2)

这听起来像mod_negotiation在不需要时做它的事情。该模块将尝试将请求URI的文件映射与“接近”所请求文件的多个不同文件进行匹配。您可以通过关闭Multiviews选项将其关闭。从您看到Options语句的vhost / server配置中删除它,或者您可以在htaccess中尝试否定它:

Options -Multiviews