.htaccess 重写以将根 URL 重定向到子目录 [英] .htaccess rewrite to redirect root URL to subdirectory

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

问题描述

试图得到

www.example.com

直接去

www.example.com/store

我尝试了多位代码,但没有任何效果.

I have tried multiple bits of code and none work.

我尝试过的:

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^(.+)www.example.com$
RewriteRule ^/(.*)$ /samle/%1/$1 [L]

我做错了什么?

推荐答案

您可以使用重写规则,该规则使用 ^$ 表示根并将其重写到您的/store 目录,如下所示:

You can use a rewrite rule that uses ^$ to represent the root and rewrite that to your /store directory, like this:

RewriteEngine On
RewriteRule ^$ /store [L]

这篇关于.htaccess 重写以将根 URL 重定向到子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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