Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 从网站URL隐藏index.php_.htaccess_Redirect - Fatal编程技术网

.htaccess 从网站URL隐藏index.php

.htaccess 从网站URL隐藏index.php,.htaccess,redirect,.htaccess,Redirect,我正在使用htaccess重写引擎使URL看起来更漂亮, 从www.mysite.com/index.php?pag=home到www.mysite.com/pag/home 这条规则适用 RewriteRule ^pag/([^/]+)$ index.php?pag=$1 [L,QSA,NC] 但是,当我访问www.mysite.com时,它会将我重定向到www.mysite.com/index.php 有没有办法重定向到www.mysite.com/pag/home 我试过了 redire

我正在使用htaccess重写引擎使URL看起来更漂亮, 从www.mysite.com/index.php?pag=home到www.mysite.com/pag/home

这条规则适用

RewriteRule ^pag/([^/]+)$ index.php?pag=$1 [L,QSA,NC]
但是,当我访问www.mysite.com时,它会将我重定向到www.mysite.com/index.php 有没有办法重定向到www.mysite.com/pag/home

我试过了

redirect 301 /index.php http://www.mysite.com/pag/home

但是当我尝试访问www.mysite.com时,浏览器会显示我的页面不存在错误

这是Drupal用来创建漂亮URL的规则,您的URL应该非常相似: 重写规则^.*$index.php?q=$1[L,QSA]


您的规则仅与包含pag的url匹配,但您确实希望命中每个url。

问题在于此重定向规则

redirect 301 /index.htm http://www.mysite.com/index.php

不是真的,因为我在子文件夹上有一些独立的服务,所以我不希望在您转到mysite.com/service1时重定向到www.mysite.com/index.php?pag=service1Ah,我理解。您仍然可以使用该规则,但必须更加明确地说明您希望它如何重定向。使用^$而不是^.*$将只针对空URL。