PHP - .htaccess清除URL不起作用

时间:2015-07-19 11:41:40

标签: php html apache .htaccess mod-rewrite

为了测试目的,我设置了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。

现在我已经尝试了几乎所有干净网址的谷歌必须提供的(大约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。 但是,如果我手动将网址更改为index.php/whatever,它确实有效但返回一个空数组。

那么我怎样才能获得干净的URL来加载页面并清理字符串查询呢?

1 个答案:

答案 0 :(得分:2)

请尝试以下规则:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?motionpicturepicker\.com$ [NC]
RewriteRule (.*) http://furff.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule (.*) http://%1/$1 [R=301,L]

RewriteCond %{THE_REQUEST} \s/+index\.php\?film=([^\s&]+) [NC]
RewriteRule ^ index/%1? [R=301,L]

RewriteRule ^index/([^/]+)/?$ index.php?film=$1 [NC,L,QSA]

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php [L]

RewriteCond %{REQUEST_FILENAME}\.html -f 
RewriteRule ^(.*)$ $1.html [L]