mod_rewrite将根uri重定向到index.php [英] mod_rewrite redirect root uri to index.php

查看:85
本文介绍了mod_rewrite将根uri重定向到index.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.htaccess文件

I have a .htaccess file

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?q=$1 [QSA]

如果我输入网址www.domain.com/something以及已加载的CSS和JS文件,效果很好.
如果我仅输入www.domain.com(不带任何参数),则问题开始-浏览器显示为空白.我需要添加什么,以便www.domain.com打开index.php,并且仍然会加载所有css文件?

It works fine if i enter url www.domain.com/something and also css and js files ar loaded.
The problem begins if i enter just www.domain.com (without any params) - browser displays blank. What i need to add so that www.domain.com opens index.php and still all the css files will load?

我尝试过

RewriteRule . /index.php [QSA,L] 

但是它没有加载任何CSS文件,因为我知道它只是将所有内容都重定向到index.php(^ $而不是.也将所有内容都重定向到index.php)

but it then none of css files are loaded because I understand that it simply redirects everything to index.php (^$ instead of . also redirects everything to index.php)

我还尝试在index.php的开头添加内容,以便www.domain.com可以在php端重定向

I also tried adding at the beginning of index.php so www.domain.com would redirect at the php side

header("Location: www.domain.com/begin");

但仍然无法正常工作,因为没有加载任何东西!

but still it is not working because nothing is loaded!

推荐答案

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js)$
RewriteRule .* /index.php [L,R=302]

应加载CSS,javascript和图像.

Should load the CSS, javascript and images.

这篇关于mod_rewrite将根uri重定向到index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆