使用mod_rewrite重写重定向的URL

时间:2010-09-20 23:37:33

标签: apache url mod-rewrite redirect

这是我的设置:

我的网站位于www.cabsh.org/drupal

我想用mod_rewrite做两件事:

  1. 将www.cabsh.org重定向到http://www.cabsh.org/drupal/index.php(我得到了这个)
  2. 重写/www.cabsh.org/drupal/index.php至www.cabsh.org/site/index.php
  3. 我无法想象如何实现第二点。我正在使用.htaccess文件,因为我无法使用主服务器配置。谁能帮助我让这个工作?

    谢谢!

1 个答案:

答案 0 :(得分:1)

从我的评论中得到的结果,你只需要这样的东西:

RewriteEngine on

# Prevent a request directly to the /drupal folder
RewriteCond %{THE_REQUEST} ^[A-Z]+\s/drupal/
RewriteRule ^drupal/(.*)$ /site/$1 [R=301,L]

# Change a request for /site/(anything) to /drupal/(anything)
RewriteRule ^site/(.*)$ /drupal/$1

但要小心,因为Drupal(位于Drupal文件夹中)可能会生成指向/ drupal而不是/ site的链接,这似乎不是您想要的。

相关问题