通过 htaccess 基于域重定向到不同的 PHP 文件
你好。
事情是这样的:
我这里有两个域 [http://www.myproject.com 和
[http://www.myproject.com.br .. 在我的根文件夹中,我拥有所有的东西
我的项目包括两个“索引”:“index-en.php”用于英语和
“index.php”为葡萄牙语。
我可以在 htaccess 中使用一些技巧将我的用户重定向到一个吗
这些文件的数量取决于域? ..类似:
[http://www.myproject.com [OR]
[http://myproject.com 重定向到 [http://www.myproject.com/index-en.php
和
[http://www.myproject.com.br [或] [http ://myproject.com.br 重定向到
[http://www.myproject.com.br/index.php
??
抱歉,如果这是一个愚蠢的问题,但我几乎疯狂地寻找教程
互联网上,我无法得到有效的东西或一些回应(如果可能的话)或只是一个愚蠢的问题..有人可以给我一些指导吗?
也许有一些带有条件目录索引的解决方案(我不知道这是否可能)。
非常感谢
实际上我的 .htaccess 中有这个:
ErrorDocument 404 /404.php
<IfModule mod_rewrite.c>
#Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^myproject.com$ [NC]
RewriteRule ^(.*)$ http://www.myproject.com/index-en.php [R=301,L]
RewriteCond %{HTTP_HOST} ^myproject.com.br$ [NC]
RewriteRule ^(.*)$ http://www.myproject.com.br/ [R=301,L]
</IfModule>
这只是执行“非 www 到 www” - 工作正常
Domain based redirect to different PHP files via htaccess
Hello there.
Here's the thing:
I have two domains here [http://www.myproject.com and
[http://www.myproject.com.br .. In my root folder i have all the stuff for
my projects including two "indexes": "index-en.php" for english and
"index.php" for portuguese.
Can i have some trick in htaccess that redirect my users to one
of these files depending on domain? .. something like:
[http://www.myproject.com [OR]
[http://myproject.com redirect to [http://www.myproject.com/index-en.php
and
[http://www.myproject.com.br [OR] [http://myproject.com.br redirect to
[http://www.myproject.com.br/index.php
??
Sorry if this is a stupid question but im almost crazy looking for tutorials over
the internet and i cant get something that works or some response if this is possible or just a stupid question .. Can someone please give me some direction?
Maybe some solution with a conditional directoryIndex (I dont know if that's possible).
thanks a lot
Actually i have this in my .htaccess:
ErrorDocument 404 /404.php
<IfModule mod_rewrite.c>
#Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^myproject.com$ [NC]
RewriteRule ^(.*)$ http://www.myproject.com/index-en.php [R=301,L]
RewriteCond %{HTTP_HOST} ^myproject.com.br$ [NC]
RewriteRule ^(.*)$ http://www.myproject.com.br/ [R=301,L]
</IfModule>
This just does the "non www to www" - that works correctly
发布评论
评论(2)
这应该做你想做的。
RewriteCond
技巧在这里可能有点矫枉过正,但它确实使添加额外的语言变得更容易:This should do what you want. The
RewriteCond
trickery is probably a bit overkill here, but it does make adding extra languages easier: