首页 文章

apache htaccess用别名重写

提问于
浏览
3

我们正在更改我们的域名,这适用于独立应用程序 . 在Apache虚拟主机文件中,DocumentRoot是/ var / www / website / html,而不是/ var / www / example / html,如下所示:

Alias /apps/dept /var/www/example/html/apps/dept
<Directory "/var/www/example/html/apps/dept/">
   Options FollowSymLinks
   AllowOverride All
   Order allow,deny
   Allow from all
</Directory>

我将.htaccess文件放在/ var / www / example / html / apps / dept目录中,如下所示:

RewriteEngine On
 RewriteBase /apps/dept/
 RewriteCond %{HTTP_HOST} ^example.orgname.state.tx.us/apps/dept [NC]
 RewriteRule ^(.*)$ http://example.orgname.texas.gov/apps/dept/$1 [L,R=301]

这似乎遵循这里推荐的,http://httpd.apache.org/docs/current/mod/mod_rewrite.htmlApache : How to Use Rewrite Engine Inside Alias . 我看不出结果 . 新域在VH文件中也有一个虚拟主机配置 . 同样的基本重写适用于我们的Drupal网站,该网站不使用别名 . 使用附加的应用程序路径名重写域名可能需要进行哪些更改? RewriteBase不正确吗?

谢谢 .

2 回答

  • 2

    所以你只想重定向 /apps/dept/ ,对吗?这应该工作 . 将它作为 .htaccess 或在 example.orgname.state.tx.us 的Apache配置中放置,所有都应该按预期工作 .

    RewriteEngine on
    RewriteRule ^/apps/dept/(.*)$ http://example.orgname.texas.gov/apps/dept/$1 [NC,L,R=301]
    

    所以现在,任何请求都会转到此URL

    http://example.orgname.state.tx.us/apps/dept/
    

    现在转到此网址:

    http://example.orgname.texas.gov/apps/dept/
    

    并且URL的右侧的任何请求参数也将被传递 .

    EDIT 重读你在这里写的内容:

    我将.htaccess文件放在/ var / www / example / html / apps / dept目录中,如下所示 .

    我上面描述的 .htaccess 应该放在 /var/www/example/html/ 而不是 /apps/dept 子目录中 .

    但是如果你想从 /apps/dept 中放置 .htaccess 的相同行为,那么使用:

    RewriteEngine on
    RewriteRule ^(.*)$ http://example.orgname.texas.gov/apps/dept/$1 [NC,L,R=301]
    

    这样,从 /apps/dept 发出的任何请求都将 example.orgname.texas.gov/apps/dept/ 包括 /apps/dept 的子目录,例如 /apps/dept/test_app1/apps/dept/test_app2/apps/dept/test_app3 .

    或者试试这个:

    RewriteEngine on
    RewriteRule (.*)$ http://example.orgname.texas.gov/apps/dept/$1 [NC,L,R=301]
    

    注意我删除了 ^ ,它会强制 RewriteRule 与URL的开头匹配 .

  • 0

    您无法在 %{HTTP_HOST} 变量中匹配请求URI,它只匹配域名 . 张你的统治:

    RewriteEngine On
     RewriteBase /apps/dept/
    
     RewriteCond %{HTTP_HOST} ^example\.orgname\.state\.tx\.us$ [NC]
     RewriteRule ^(.*)$ http://example.orgname.texas.gov/apps/dept/$1 [L,R=301]
    

相关问题