php – .htaccess for apache 2.2不适用于apache 2.4 vagrant开发框

前端之家收集整理的这篇文章主要介绍了php – .htaccess for apache 2.2不适用于apache 2.4 vagrant开发框前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
下面的.htaccess文件适用于各种托管网站,所有这些都在apache 2.2上,但云服务器上的测试环境和新网站都在apache 2.4上运行.

问题是除非添加包括.PHP的完整文件名,否则对PHP文件的访问不再有效. www.example.com/about.PHP而不是www.example.com/about

对以下任何帮助都非常赞赏 – 理想情况下使用.htaccess可以同时使用2.2和2.4 apache.

  1. Options -Indexes +multiviews
  2. RewriteEngine On
  3. RewriteBase /
  4.  
  5. ErrorDocument 404 /404.PHP
  6. #ErrorDocument 500 /500.PHP
  7.  
  8. # Add www.
  9. RewriteCond %{HTTP_HOST} !^www\.
  10. #RewriteRule ^(.*)$http://www.%{HTTP_HOST}/$1 [R=301,L]
  11.  
  12. # Remove .PHP
  13. #RewriteCond %{THE_REQUEST} ^GET\ (.*)\.PHP\ HTTP
  14. #RewriteRule (.*)\.PHP$$1 [R=301]
  15.  
  16. # remove index
  17. RewriteRule (.*)/index$$1/ [R=301]
  18.  
  19. # remove slash if not directory
  20. RewriteCond %{REQUEST_FILENAME} !-d
  21. RewriteCond %{REQUEST_URI} /$
  22. RewriteRule (.*)/ $1 [R=301]
  23.  
  24. # add .PHP to access file,but don't redirect
  25. RewriteCond %{REQUEST_FILENAME}.PHP -f
  26. RewriteCond %{REQUEST_URI} !/$
  27. RewriteRule (.*) $1\.PHP [L]

– -编辑 – –

下面是用于VirtualHost的apache 2.4 000-default.conf

  1. PHP_value auto_prepend_file /vagrant/www/fixdocroot.PHP
  2.  
  3. <VirtualHost *:80>
  4. ServerName dev.dev
  5. ServerAlias *.dev
  6. UseCanonicalName Off
  7.  
  8. VirtualDocumentRoot "/vagrant/www/%-2+/public_html"
  9.  
  10. <Directory /vagrant/www>
  11. AllowOverride All
  12. Require all granted
  13. </Directory>
  14. </VirtualHost>

—进一步编辑—
Apache错误日志如下:

  1. [Mon Jan 11 09:26:35.751982 2016] [core:notice] [pid 1812] AH00094: Command line: '/usr/sbin/apache2'
  2. [Mon Jan 11 09:44:22.816423 2016] [:error] [pid 1892] [client 192.168.33.1:49762] PHP Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in PHP.ini and use the PHP://input stream instead. in Unknown on line 0,referer: http://speechlink-primary.dev/infant/assessment/start/15
  3. [client 192.168.33.1:49804] AH00687: Negotiation: discovered file(s) matching request: /vagrant/www/domainname/public_html/page-name (None could be negotiated).
.htaccess文件的第一行似乎是问题:
  1. Options -Indexes +multiviews

Apache documentation

The effect of MultiViews is as follows: if the server receives a request for /some/dir/foo,if /some/dir has MultiViews enabled,and /some/dir/foo does not exist,then the server reads the directory looking for files named foo.*,and effectively fakes up a type map which names all those files,assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client’s requirements.

我相信这会干扰RewriteRules – 在我对Apache 2.4流浪盒的测试中,从该行删除多视图似乎已经解决了这个问题.

猜你在找的PHP相关文章