Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
使用Apache重写内部url_Apache_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

使用Apache重写内部url

使用Apache重写内部url,apache,.htaccess,mod-rewrite,redirect,Apache,.htaccess,Mod Rewrite,Redirect,我试图做的是将请求重定向到,而不向用户显示任何重定向。我在htaccess中这样做: RewriteEngine On RewriteRule ^tel\.php$ /default/index/tel [NC,L] RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 然而,重定向向用户显示了我试图避免的内容(HTTP/1.1 301永久移动) 如何解决此问题?更

我试图做的是将请求重定向到,而不向用户显示任何重定向。我在htaccess中这样做:

RewriteEngine On

RewriteRule ^tel\.php$ /default/index/tel [NC,L]


RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
然而,重定向向用户显示了我试图避免的内容(HTTP/1.1 301永久移动)


如何解决此问题?

更改规则的顺序,如果需要,可以选择添加尾随斜杠

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteRule ^tel\.php$ /default/index/tel [NC,L]
# make it as this if /default/index/tel/ is a real directory
# RewriteRule ^tel\.php$ /default/index/tel/ [NC,L]
请确保在清除浏览器缓存后对其进行测试