1

我正在尝试让 aphdigital.org/GVH/ 重定向到 gvh.aphdigital.org,并将 aphdigital.org/GVH/something/ 重定向到 gvh.aphdigital.org/something/,但我遇到了很多困难。我尝试了这个问题的代码,但它不起作用。下面被注释掉的代码块也显示了重定向失败的尝试。我究竟做错了什么?如果我可以访问 httpd.conf,我会启用日志记录,但我只有 FTP 访问权限。我知道 apache 正在读取这个文件,因为语法错误似乎会导致 500 错误。

这是我的 .htaccess 文件:

# Remember to enable display_errors on development environments only.
<IfModule mod_php5.c>
    php_value display_errors 1
    php_flag register_globals off
</IfModule>

RewriteEngine on

# If know that mod_rewrite is enabled, but you are still getting mod_rewrite errors,
# uncomment the line below and replace "/" with your base directory.
# RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^admin/ - [C]
RewriteRule .* admin/index.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php

# Added this on Jan. 4, 2013 to redirect from old URL to new. Doesn't seem to be working. 
RewriteCond %{HTTP_HOST} ^www.aphdigital.org/GVH$
RewriteCond %{HTTP_HOST} ^www\.aphdigital\.org/GVH$
RewriteRule ^gvh/(.*)$ http://gvh.aphdigital.org/$1 [L,QSA,R=301]
# End of Jan. 4 add.

#TEST for redirect added April 3. Also doesn't work. 
# To redirect /mysub/foo to http://mysub.mysite.co.uk/foo
#RewriteCond %{HTTP_HOST} ^(www\.)?(aphdigital\.org)$ [NC]
#RewriteRule ^(gvh)/?(.*)$ http://$1.%2/$2 [R=301,L,NC] 

#TEST2, code from Stackoverflow question 
#Options +FollowSymLinks -MultiViews
#RewriteEngine on
#RewriteBase /

# To redirect http:://www.mysite.co.uk/ to http:://mysite.co.uk/
#RewriteCond %{HTTP_HOST} ^www\.(aphdigital\.org)$ [NC]
#RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

# To redirect /mysub/foo to http://mysub.mysite.co.uk/foo
#RewriteCond %{HTTP_HOST} ^(www\.)?(aphdigital\.org)$ [NC]
#RewriteRule ^(gvh)/?(.*)$ http://$1.%2/$2 [R=301,L,NC] 
#END TEST 2

#Intentionally breaking to see if reading .htaccess. Yep, this breaks it. 
#<directory / ></directory> 

<FilesMatch "\.(php|ini)$">
 Order Allow,Deny
 Deny from all
</FilesMatch>

<Files index.php>
Allow from all
</Files>

# Uncomment the lines below in order to enable caching of some files via Apache (after a finished site has gone live)
<IfModule mod_expires.c>
#  <FilesMatch "\.(js|ico|gif|jpg|png|css)$">
#       ExpiresActive on
#       ExpiresDefault "access plus 10 day"
#   </FilesMatch>
</IfModule>

这适用于运行 Omeka CMS 的站点。

4

1 回答 1

1

URL 路径GVH不是 的一部分%{HTTP_HOST},因此应该是

RewriteCond %{HTTP_HOST} ^(?:www\.)?aphdigital\.org$
RewriteRule ^gvh/(.*)$ http://gvh.aphdigital.org/$1 [R,L,NC]

永远不要在启用的情况下进行测试,有关详细信息301,请参阅此答案提示调试 .htaccess 重写规则

于 2013-04-03T22:36:33.543 回答