2012-06-14 133 views
2

我該怎麼做?htaccess,子文件夾重寫爲index.php

主要環節:

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

皈依:

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

我試着用這樣的:

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

但不工作。

回答

1

啓用mod_rewrite的,並通過httpd.conf的.htaccess,然後把這個代碼在你.htaccessDOCUMENT_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

這應該爲你工作:

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

編輯:

由於@anubhava發佈在他的answer,你應該che ck請求的文件或目錄是否存在於RewriteCond中。

0

這應該工作:

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