htaccess将所有404重定向到带有参数的index.php,但不要更改地址栏

时间:2016-01-18 15:35:23

标签: apache .htaccess mod-rewrite redirect url-rewriting

我想要做的是将所有不存在的URL重定向到index.php?q =%URL%,例如:
www.example.com/ggg将重定向到www.example.com/index.php?q=ggg

但是,我希望地址栏仍然显示www.example.com/ggg

到目前为止我得到的是:

Options +FollowSymLinks
RewriteEngine On

# redirect all requests to non-existing resources to special handler
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/? /index.php?q=$1 [L,NC,R]

但它不断更改地址栏,而且我不确定它是否一直有效。

有什么建议吗? 感谢

1 个答案:

答案 0 :(得分:2)

如果要将错误页面重写为index.php,请删除R标志。

Options +FollowSymLinks
RewriteEngine On

# redirect all requests to non-existing resources to special handler
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?q=$1 [L,NC]