.htaccess重写规则php重定向文件夹到另一个

问题描述:

我有一个文件夹测试。如果一个人导航到文件夹测试,我希望浏览器显示新的。.htaccess重写规则php重定向文件夹到另一个

服务器上不存在新的文件夹,我只是希望它显示为新的,它在服务器上链接到文件夹测试。

这是我的配置(的httpd-vhosts.conf):

<VirtualHost server.com> 
    DocumentRoot "c:/www/" 
    ServerName server.com 
    Alias /new "c:/www/test" 
    <Directory "c:/www/"> 
     Options +Indexes +Includes +FollowSymLinks +MultiViews 
     AllowOverride All 
     Require all granted 
    </Directory> 
</VirtualHost> 

所以,要清楚,如果有人浏览到:

  • server.com/test(服务器使用的文件夹测试,但server.com/new显示在浏览器中
  • server.com/(与上面相同=> server.com/new显示在浏览器中)
  • server.com/index.php(服务器使用来自文件夹t的index.php est,浏览器显示server.com/new/index.php
  • server.com/test/index.php(与上面相同)
  • server.com/test/folder2/index.php?variable=1(服务器使用文件夹test/folder2中的index.php并将变量提供给php文件。浏览器显示server.com/new/folder2/index.php?variable=1)

我试过不同的.htaccess重写,但我不能得到它的工作。

也许我不必使用别名?

不要只给我一个链接到Apache手册,因为我读过它,但无法得到它的工作...

你不需要Alias的这使注释掉:

Alias /new "c:/www/test" 

然后有下列规则:

<VirtualHost server.com> 
    DocumentRoot "c:/www/" 
    ServerName server.com 

    <Directory "c:/www/"> 
     Options +Indexes +Includes +FollowSymLinks +MultiViews 
     AllowOverride All 
     Require all granted 
    </Directory> 

    DirectoryIndex index.php 
    RewriteEngine On 

    RewriteRule ^/?$ /new/ [L,R=301] 

    RewriteCond %{THE_REQUEST} \s/+test(\S*)\s [NC] 
    RewriteRule^/new%1 [R=301,NE,L] 

    RewriteRule ^/?new(/.*)?$ /test$1 [L,NC] 

</VirtualHost> 
+0

我在不同的时区比你我觉得很,很抱歉为我迟到的答复。我正在测试它,但我认为我仍然在做错事。我会再测试一下,然后让你知道。我收到500错误。 –

+0

耶,这个伎俩!只有当我访问server.com时,它才会将我重定向到server.com/new。顺便说一句,R = 301必须在那里?这意味着永久重定向。而且我不需要添加QSA(从请求追加查询字符串到替换的URL)? –

+1

好吧再试试我的更新规则 – anubhava