我有一个简单的主页(index.html
),它有一个超链接到名为main
的子文件夹,其中包含index.html
。你可以看到在相同:rajiviyer.inURL从根到子文件夹重写htaccess
代码为超链接:
<p>Go to sub folder page - <a href="Main/">Main</a></p>
如何配置.htaccess
这个的话,我可以直接访问http://site_name/main/*.html
?
我有一个简单的主页(index.html
),它有一个超链接到名为main
的子文件夹,其中包含index.html
。你可以看到在相同:rajiviyer.inURL从根到子文件夹重写htaccess
代码为超链接:
<p>Go to sub folder page - <a href="Main/">Main</a></p>
如何配置.htaccess
这个的话,我可以直接访问http://site_name/main/*.html
?
您可以用PHP做到这一点:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.domain.de/main");
header("Connection: close");
?>
或者,就像你真正想要的,用的.htaccess项:
RewriteEngine On
Redirect 301/http://www.domain.de/main
谢谢,我创建与下方的.htaccess项: 选项+的FollowSymLinks RewriteEngine叙述在 #设置默认页目录的index.php 的DirectoryIndex的index.php index.html的 #重定向到www 的RewriteCond%{HTTP_HOST}^rajiviyer.in [NC] 重写规则^(。*)$ http://www.rajiviyer.in/$1 [R = 301 ,L] 重定向301/http://www.rajiviyer.in/main 但我得到ERR_TOO_MANY_REDIRECTS 我无法看到主页。我访问该网站时直接遇到此错误。 – Rajiv
你只是想从根目录重定向到这个子文件夹。或从所有链接到/主?试试上面的代码。通过您的代码,您可以循环路由。 – errorcode
是的,只从根到这个子文件夹。 – Rajiv
鉴于你的评论,请尝试以下改为:
Options +FollowSymLinks -Multiviews
# Set default page for a directory to index.php
DirectoryIndex index.php index.html
# Turn on the rewrite engine for this override
RewriteEngine On
# Force www.
RewriteCond %{HTTP_HOST} ^rajiviyer\.in [NC]
RewriteRule ^(.*)$ http://www.rajiviyer.in/$1 [R=301,L]
# Redirect site root to main directory
RewriteRule ^$ /main/ [R=302,L]
一旦您开心,请将302
更改为301
以使浏览器和搜索引擎缓存的重定向。
请尝试改善拼写。虽然这里不需要高水平的英语,但如果遵循这个[六个简单的拼写规则],您可以得到更好的接受度(http://meta.stackoverflow.com/questions/291362/my-question-was-downvoted-closed - 因为,它 - 是 - 完全的,语法,错误-WH/291370#291370)。 – peterh
@peterh *这些//对不起,但我无法抗拒;) – SWdV
@SWdV抵抗什么? – peterh