PHP - .htaccess 干净的 URL 不起作用

标签 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。 但是,如果我手动将 url 更改为 index.php/whatever,它确实可以工作,但返回一个空数组。

那么我怎样才能获得干净的网址来加载页面并让干净的字符串查询也能工作呢?

最佳答案

尝试这些规则:

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]

关于PHP - .htaccess 干净的 URL 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31500812/

相关文章:

php - 未找到带有App Engine标准类 'Facade\Ignition\IgnitionServiceProvider'的Laravel

php - mysql查询错误输出

javascript - 我必须添加什么样的脚本才能使框自动对齐?

Apache 2 : Cannot access Userdir - Forbidden

javascript - 更改浏览器窗口底部的链接鼠标悬停文本

Php Mysql 选择带有关联数组的列

javascript - 为什么这个 AJAX 表单没有提交?

javascript - 拖动滚动包含 float div 的 div

javascript - 停止从 javascript 提交表单

apache - 如何在 apache 中添加请求 ID 并将其转发到底层系统?