htaccess将所有网址重定向到默认配置文件页面

时间:2014-01-02 11:27:58

标签: php .htaccess redirect

我的.htaccess有问题。发生的事情是通过添加这个改变了htaccess: -

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f

但它之后它还将域之后的所有URL重定向到某个默认的配置文件页面,例如:如果我输入domain.com/edit.php它显示profile.php页面但edit.php不存在而不是它应显示404页面但不会发生。

这是我的.htaccess,是不是也影响了我的搜索引擎优化。

Options +Indexes
# or #
IndexIgnore *
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9._-]+)$ profile.php?u=$1 
RewriteRule ^([a-zA-Z0-9._-]+)/$ profile.php?u=$1
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

1 个答案:

答案 0 :(得分:1)

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

表示如果浏览器中具有指定名称的文件不存在,或者浏览器中的目录不存在,则继续执行这些字符串下面的重写规则

在您的情况下,规则是

RewriteRule ^([a-zA-Z0-9._-]+)$ profile.php?u=$1 

因此,如果您希望在找不到页面的情况下发生任何特定情况,请在带有-d-f标记的字符串下添加一些其他规则(重定向到404页面等)。

或删除这些字符串并添加指向您的404错误文档的链接

ErrorDocument 404 /errordoc.php

或将index.php链接为错误文档

ErrorDocument 404 /index.php
相关问题