.htaccess htaccess重定向问题
我的.htaccess如下所示:.htaccess htaccess重定向问题,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我的.htaccess如下所示: RewriteEngine on RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)|(\.swf)|(\.xpi)|(\.ico)|(\.src)$ RewriteCond %{REQUEST_URI} ^(.*)$ #RewriteCond %{REQUEST_FILENAME} ! -f RewriteRule (.*)$ view.php?picid=
RewriteEngine on
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)|(\.swf)|(\.xpi)|(\.ico)|(\.src)$
RewriteCond %{REQUEST_URI} ^(.*)$
#RewriteCond %{REQUEST_FILENAME} ! -f
RewriteRule (.*)$ view.php?picid=$1 [L]
问题是,当我访问www.example.com
时,它将我发送到view.php
。在我的根目录中有一个index.php
文件。如何使.htaccess忽略索引文件?从第四行删除
,并删除感叹号(!)和-f
RewriteCond %{REQUEST_FILENAME} !-f
这一行表示,如果服务器上不存在该文件,在本例中为index.php
,则继续执行下面的重写
还要检查您是否有DirectoryIndex
,以及是否有任何有效的目录
DirectoryIndex index.php
RewriteCond %{REQUEST_FILENAME} !-d
这将为您提供更干净的版本:
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ view.php?picid=$1 [L]
首先将index.php
设置为默认文件。然后运行重写引擎,如果请求的文件在服务器上不作为文件或目录存在,则会将内容传递到view.php
文件并运行其魔力。尝试以下规则:
RewriteCond %{REQUEST_URI} !.*\.(gif|jpg|png|css|js|php|swf|xpi|ico|src)$ [OR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+) view.php?picid=$1 [L]
我所做的重要改变是:
- 第一个重写条件中的正则表达式有错误。
锚定仅应用于变更中的最后一个选项$
- 第二个
指令无效RewriteCond
- 注释掉的第三个
将执行您想要的操作:检查请求的URI路径是否可以映射到现有文件RewriteCond
- 将量词从零个或多个字符更改为一个或多个字符。这将在请求
时排除空URI路径/