.htaccess 使用.haccess重定向到特殊路由

1qczuiv0  于 6个月前  发布在  其他
关注(0)|答案(1)|浏览(83)

我想从example.com重定向到example.com/home。默认的.haccess文件是:为什么下面的代码不起作用?

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php81” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php81 .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit.

字符串
为了重定向到home路由,我在.haccess中添加了以下代码:

# Redirect to example.com/home
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteRule ^index\.html$ - [L]
    RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.example\.com$
    RewriteRule ^(.*)$ "http://example.com/home" [R=301,L]
</IfModule>


现在,.haccess文件内容是

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php81” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php81 .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit.

# Redirect to example.com/home
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteRule ^index\.html$ - [L]
    RewriteCond %{HTTP_HOST} ^example\.ir$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.example\.ir$
    RewriteRule ^(.*)$ "http://example.com/home" [R=301,L]
</IfModule>


但它不工作,我遇到以下错误:
内部服务器错误服务器遇到内部错误或配置错误,无法完成您的请求。
如何从example.com重定向到example.com/home
我在网上搜索了一下,发现了下面的问题,但这是我的问题。Want to Change URL from www.domain.com/home to www.domain.com

mzmfm0qo

mzmfm0qo1#

@CBroe解决了我的问题。
@CBroe评论:^(.*)$匹配任何可能的URL路径,所以它也会重定向/foobar,当然也会重定向/home。您需要检查空URL路径,所以这将是^$。

相关问题