无法让.htaccess工作

时间:2013-04-04 03:52:38

标签: apache .htaccess

作为一名经验丰富的网络开发者,我觉得这是一个白痴。不知何故,我倾向于遇到.htaccess的问题。我正在尝试使用以下内容将/wiki中的所有请求路由到我的index.php ...

RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./ /index.php [L]

虚拟主持人:

<VirtualHost *:80>
        ServerName mysite.local
        DocumentRoot "/var/www/mysite/public_html"
        <Directory "/var/www/mysite/public_html">
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
</VirtualHost>

我正在尝试访问http://mysite.local/wiki/asdf并收到404错误。

Apache的错误日志没有显示任何内容

3 个答案:

答案 0 :(得分:0)

如果/wikipublic_html根文件夹中的现有文件夹,并且您的index.php文件位于wiki文件夹中,那么您可以尝试以下操作:

RewriteEngine On
RewriteBase /wiki
RewriteRule index\.php - [F,L]
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule .* index.php [L]

如果wiki文件夹不存在,并且您正在根目录下完成所有工作:

RewriteEngine On
RewriteBase /
RewriteRule index\.php - [F,L]
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule wiki/(.*) index.php/$1 [L]

答案 1 :(得分:0)

现在试一试!要将不存在的/wiki/wiki/以及/wiki/$var重写为/index.php

RewriteCond %{REQUEST_URI} ^/wiki/?
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /index.php

答案 2 :(得分:0)

我最终需要Yii Framework使用的内容......

RewriteEngine On

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php