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 如何使用htaccess将页面重定向到文件夹?_.htaccess - Fatal编程技术网

.htaccess 如何使用htaccess将页面重定向到文件夹?

.htaccess 如何使用htaccess将页面重定向到文件夹?,.htaccess,.htaccess,无法找出此重定向不起作用的原因。这不是将页面重定向到目录的正确方法吗(参见最后一行) 不要混合使用mod_rewrite和mod_alias。将代码更改为: AddDefaultCharset UTF-8 ErrorDocument 404 /404.html AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascr

无法找出此重定向不起作用的原因。这不是将页面重定向到目录的正确方法吗(参见最后一行)


不要混合使用mod_rewrite和mod_alias。将代码更改为:

AddDefaultCharset UTF-8
ErrorDocument 404 /404.html
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript
ExpiresActive On
ExpiresDefault "access plus 1 minute"

RewriteEngine On

RewriteRule ^folder/name/main\.html‎$ /a-nother-folder [L,NC,R=301]

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

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.html [NC,L]

也可以尝试在其他浏览器中进行测试。

不要将mod_rewrite和mod_alias混用。将代码更改为:

AddDefaultCharset UTF-8
ErrorDocument 404 /404.html
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript
ExpiresActive On
ExpiresDefault "access plus 1 minute"

RewriteEngine On

RewriteRule ^folder/name/main\.html‎$ /a-nother-folder [L,NC,R=301]

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

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.html [NC,L]

也可以尝试在其他浏览器中进行测试。

尝试使用完全限定的URL作为目标URL(即
http://example.com/a-nother-folder
)<代码>重定向对相对路径不起作用。谢谢Jason,成功了!尝试使用完全限定的URL作为目标URL(即
http://example.com/a-nother-folder
)<代码>重定向对相对路径不起作用。谢谢Jason,成功了!感谢您指出“不要混合使用mod_rewrite和mod_alias”感谢您指出“不要混合使用mod_rewrite和mod_alias”