我该怎么做?
主要链接:
http://www.domain.com/?link=whatever/something/everythting
转换为:
http://www.domain.com/whatever/something/everythting
我试过这个:
RewriteEngine On
RewriteRule ^([^/]*)$ index.php?link=$1 [L]
但不行。
答案 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]