【发布时间】:2015-10-08 15:35:49
【问题描述】:
出于测试目的,我设置了 index.php,其中仅包含:
<?php echo var_dump($_GET); ?>
我的 htaccess 看起来像这样:
RewriteEngine on
#Alternate default index page
DirectoryIndex home.php
# To set your custom php.ini, add the following line to this file:
# suphp_configpath /home/yourusername/path/to/php.ini
# php_value mbstring.func_overload 4 # Required for PWSB support. Please do not uncomment this line.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [L]
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^motionpicturepicker\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.motionpicturepicker\.com$
RewriteRule ^/?$ "http\:\/\/furff\.com" [R=301,L]
据我所知,这也删除了 .php 和 .html 扩展名以及 www。
现在我已经尝试了几乎所有谷歌必须提供的干净 url 示例(大约 20 种),但没有一个完全可以正常工作。
添加这是我最接近的:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?film=([^\s&]+) [NC]
RewriteRule ^ index/%1? [R=301,L]
RewriteRule ^index/([^/]+)/?$ index.php?film=$1 [L,QSA]
这使得去index.php?film=whatever重定向到/index/whatever
不过/index/whatever返回的是Error 500 - Internal Server Error而不是index.php。
但是,如果我手动将 url 更改为 index.php/whatever 它确实有效,但返回一个空数组。
那么我怎样才能让干净的 url 加载页面和干净的字符串查询也能正常工作呢?
【问题讨论】:
标签: php html apache .htaccess mod-rewrite