【问题标题】:Mod_rewrite multi domain namesmod_rewrite 多域名
【发布时间】:2020-04-02 15:14:00
【问题描述】:

所以我在一台服务器上有 2 个域名 2 个不同的站点 我对一个域名进行了 mod-rewrite,我只想为一个域名工作,但是当我上传 .htaccess 文件时,1 个域名有效很好,但其他网站/域名显示 Not Found The requested URL was not found on this server. Additionally, a 404 Not Found _error_ was encountered while trying to use an ErrorDocument to handle the request.

如果我删除 mod rewrite 文件,第二个站点可以工作并显示,但第一个站点需要 mod rewrite 才能工作 有没有办法将mod重写设置为只运行一个域名?

只是想添加主域名在根目录中,而第二个域名在根目录中的文件中,所以我希望所有条件都适用于根目录中的域名 1 但不是域名 2位于根目录下的文件夹中。当我访问域名 2 时出现 404 错误。

    options -multiviews
    options All -Indexes
    <IfModule mod_rewrite.c>
    RewriteEngine On
 RewriteBase /
 RewriteCond %{HTTP_HOST} mydomainname.com$ [NC]
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteRule ^home$ index.php
    RewriteRule ^dashboard$ dashboard.php
    RewriteRule ^advertiser$ advertiser.php
    RewriteRule ^add_campaign$ add_campaign.php
    RewriteRule ^edit_campaign$ edit_campaign.php
    RewriteRule ^stats$ view_statistics.php
    RewriteRule ^login$ login.php
    RewriteRule ^logout$ logout.php
    RewriteRule ^withdrawals$ withdrawals.php
    RewriteRule ^register$ register.php
    RewriteRule ^report$ report.php
    RewriteRule ^referrals$ referrals.php
    RewriteRule ^contact$ contact.php
    RewriteRule ^add_wallet$ add_wallet.php
    RewriteRule ^payment_page$ payment_page.php
    RewriteRule ^forgot_password$ forgot_password.php
    RewriteRule ^my_account$ my_account.php
    RewriteRule ^(admin)($|/) - [L]
    RewriteRule ^([A-Za-z0-9-]+)/?$ view_link.php?s=$1 [L]
    RewriteRule ^page_([^/]+)/?$ pages.php?slug=$1 [L]
    </IfModule> 

【问题讨论】:

    标签: php html .htaccess


    【解决方案1】:

    RewriteConds 仅适用于紧随其后的 一个 RewriteRule,因此您必须在每一个之前重复它们。

    在这里使用否定模式可能更有意义 - 检查主机名是否不是 mydomainname.com,然后遵循一个简单的规则,“好的,我们在这里完成了” , 通过使用 [L] 标志。

    RewriteEngine On
    RewriteBase /
    # check if the host name was not mydomainname.com
    # pattern anchored at the start using ^ as well here, so that notmydomainname.com
    # would not be matched as well, and the . escaped
    # whole thing negated, by putting ! in front of it
    RewriteCond %{HTTP_HOST} !^mydomainname\.com$ [NC]
    # match absolutely anything with the .
    # don’t do any actual rewriting, by using - as the substitution
    # [L] flag to say, that’s it, we are done with the rewriting here
    RewriteRule . - [L]
    # … rest of your rules follow here
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{SCRIPT_FILENAME} !-f
    # …
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-04
      • 2015-11-29
      • 2015-09-07
      • 1970-01-01
      • 2013-01-15
      • 2015-02-02
      • 2011-04-23
      相关资源
      最近更新 更多