【问题标题】:(.htaccess) how to mod_rewrite a tilde user site to subfolder within same site(.htaccess)如何将波浪号用户站点修改为同一站点内的子文件夹
【发布时间】:2012-08-20 06:20:56
【问题描述】:

我已经在这个问题上工作了几个晚上,但没有运气。我正在尝试使用 (.htaccess) 重写网络请求 来自:cobweb.seas.gwu.edu/~mpnl 至:cobweb.seas.gwu.edu/~mpnl/joomla

我最新的 (.htaccess) 文件如下:

# turn on Rewrite
RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www.)?cobweb.seas.gwu.edu/~mpnl$
RewriteCond %{REQUEST_URI} !^/joomla/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /joomla/$1 [L]

RewriteRule ^(/)?$ joomla/index.php [L]

【问题讨论】:

    标签: apache .htaccess redirect subdirectory tilde


    【解决方案1】:

    您不能匹配带有 %{HTTP_HOST} 变量的 URI 路径,只能匹配主机。您需要包含 ~mpnl 部分作为重写基础或作为请求 URI 的一部分:

    RewriteEngine on
    
    # remove the "/~mpnl" from the end of this line, add a [NC]
    RewriteCond %{HTTP_HOST} ^(www.)?cobweb.seas.gwu.edu$ [NC]
    # add a "/~mpnl" to here
    RewriteCond %{REQUEST_URI} !^/~mpnl/joomla/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # remove the leading slash before "joomla"
    RewriteRule ^(.*)$ joomla/$1 [L]
    
    # add a condition to this:
    RewriteCond %{REQUEST_URI} !^/~mpnl/joomla/
    RewriteRule ^(/)?$ joomla/index.php [L]
    

    【讨论】:

    • 我尝试了您建议的 (.htaccess) 文件但没有成功 - 仍然收到相同的 500 内部服务器错误。我仔细检查并在服务器上启用了 mod_rewrite。我使用 textedit 编辑文件,确保文件保存为 unix 和 ansi 编码。还尝试了各种权限。我应该提到我将 (.htaccess) 文件保存到 public_html 的根目录。
    【解决方案2】:

    要在 URI 中使用 UserDirrewrite 请求,您必须设置 RewriteBase

    RewriteBase /~mpnl/
    

    【讨论】:

      猜你喜欢
      • 2011-06-03
      • 2019-08-29
      • 1970-01-01
      • 1970-01-01
      • 2013-02-24
      • 2015-11-22
      • 1970-01-01
      • 1970-01-01
      • 2021-12-22
      相关资源
      最近更新 更多