Dude
Dude

Reputation: 230

.htaccess RewriteRule php redirect folder to another

I have a folder test. If a person navigates to the folder test, I want the browser to display new.

The folder new doesn't exist on the server, I just want it to be displayed as new, which on the server is linked to the folder test.

This is my config (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>

So, to be clear, if someone browses to:

I have tried different .htaccess rewrites, but I can't get it working.

Maybe I don't have to use the alias?

Don't just give me a link to the apache manual, because I've read it, but can't get it to work...

Upvotes: 1

Views: 91

Answers (1)

anubhava
anubhava

Reputation: 785156

You don't need Alias for this so comment out:

Alias /new "c:/www/test"

Then have these rules:

<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> 

Upvotes: 1

Related Questions