htaccess rewrite to always redirect to a domain with prefix

114 Views Asked by At

I have this project I maintain which I run in XAMPP and by default the url is set to http://localhost and it will take the folder project name inside htdocs to access the content. For instance I have a folder called test so my base url should be http://localhost/test.

The issue I am facing now is, most of the link was written in something like /profile.php and it will redirect to http://localhost/profile.php instead of http://localhost/test/profile.php. I find it hard to do the testing and all when they redirect to the wrong url.

How do I write the htaccess so that it will always read http://localhost/test as the base url?

This is something I tried but since I still quite confuse with the rule so I was not able to achieve what I'm trying to do.

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /test/$1 [R=301,L]

EDIT :

All php files are under test folder at 1st level so they can be accessed by browsing as domain-url/any-file.php. In my case it should be something like http://localhost/test as the domain name and /profile.php as first uri also referring to the file profile.php

0

There are 0 best solutions below