当前位置: 动力学知识库 > 问答 > 编程问答 >

php - htaccess redirect to subdirectory by default, but open main site from link in subdirectory site

问题描述:

This is my example site

http://www.example.com/ - (main site, in English)

http://example.com/mylang/ - (site in my language)

Both the sites run with multiple installation of wordpress.

Now, when user enter my website, he must be redirected to http://example.com/mylang/ and there is a link to go to main site http://www.example.com/ if the user wants to see.

How can I do with .htaccess? I am open to get other (php or javascript redirect) solutions also.

网友答案:

On main site check if a session is set, if not redirect. (Note this must be done before any output is sent)

session_start();
if(!isset($_SESSION['been_here'])) {
     header('Location: http://example.com/mylang/');
     exit();
}

On the mylang set the session.

session_start();
$_SESSION['been_here'] = 1;

The duration of this session won't redirect on front page visits.

网友答案:

You should put below code inside .htaccess of root folder of main site

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/$
RewriteRule (.*) http://example.com/mylang [R=301,L]
分享给朋友:
您可能感兴趣的文章:
随机阅读: