htaccess,子文件夹重写为index.php

时间:2012-06-14 08:58:40

标签: .htaccess

我该怎么做?

主要链接:

http://www.domain.com/?link=whatever/something/everythting

转换为:

http://www.domain.com/whatever/something/everythting

我试过这个:

RewriteEngine On
RewriteRule ^([^/]*)$ index.php?link=$1 [L]

但不行。

3 个答案:

答案 0 :(得分:1)

通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在.htaccess目录下的DOCUMENT_ROOT中:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
# If the request is not for a valid link
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ /?link=$1 [L,QSA]

答案 1 :(得分:1)

这应该适合你:

RewriteEngine On
RewriteRule ^(.+)$ index.php?link=$1 [L]

修改

正如@anubhava在他的answer中发布的那样,你应该检查RewriteCond中是否存在所请求的文件或目录。

答案 2 :(得分:0)

这应该有效:

RewriteRule ^([^.]+)$ index.php?link=$1 [L]