通过 htaccess 基于域重定向到不同的 PHP 文件

发布于 2024-09-15 02:21:33 字数 1641 浏览 1 评论 0 原文

通过 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深空失忆 2024-09-22 02:21:33

这应该做你想做的。 RewriteCond 技巧在这里可能有点矫枉过正,但它确实使添加额外的语言变得更容易:

ErrorDocument 404 /404.php

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST}/index.php    \.com\.br/(index.php)$ [NC,OR]
RewriteCond %{HTTP_HOST}/index-en.php \.com/(index-en.php)$  [NC]
RewriteRule ^ %1

This should do what you want. The RewriteCond trickery is probably a bit overkill here, but it does make adding extra languages easier:

ErrorDocument 404 /404.php

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST}/index.php    \.com\.br/(index.php)$ [NC,OR]
RewriteCond %{HTTP_HOST}/index-en.php \.com/(index-en.php)$  [NC]
RewriteRule ^ %1
等你爱我 2024-09-22 02:21:33
RewriteCond %{HTTP_HOST}  myproject\.com$
RewriteRule ^/$  /index-en.php

RewriteCond %{HTTP_HOST}  myproject\.com\.br$
RewriteRule ^/$  /index.php
RewriteCond %{HTTP_HOST}  myproject\.com$
RewriteRule ^/$  /index-en.php

RewriteCond %{HTTP_HOST}  myproject\.com\.br$
RewriteRule ^/$  /index.php
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文