the-catalin
the-catalin

Reputation: 1308

How to make an alias in .htaccess to change a local URL

I'm pretty sure this is a duplicate but I just don't know how to find the answer to this simple problem.

So I have a local page like this:

http://example.com/mypage.php

And all I want to do is to have anyone who tries to access http://example.com/subfolder/mypage.php to actually load the page at the above location.

I don't want a redirect. http://example.com/subfolder/mypage.php does not exist as an actual path on my server, but I want to make it available via rule in .htaccess

Upvotes: 3

Views: 4496

Answers (2)

cdog
cdog

Reputation: 2084

Try this:

RewriteEngine on
RewriteRule ^subfolder/(.*) /$1

This rule rewrites every request that starts with /subfolder/ to /. Or if you need only for a specific URL-path:

RewriteEngine on
RewriteRule ^subfolder/mypage.php /mypage.php

Upvotes: 2

Sasi Varunan
Sasi Varunan

Reputation: 2864

You can add it in .htaccess

RewriteEngine On
RewriteRule  ^([^/]+)/(.*)   /$2

or use directly in httpd.conf like

<Directory /var/www/>
    Options Indexes FollowSymLinks ExecCGI
    AllowOverride None
    Order deny,allow
    Allow from all  
    RewriteEngine On
    RewriteRule  ^([^/]+)/(.*)   /$2    
</Directory>

use $1 to get subfolder and $2 to get mypage.php :)

Upvotes: 0

Related Questions