Gyro
Gyro

Reputation: 93

how do I use htaccess to redirect on test wamp server

I have a site on both a live server and locally on a wampserver. The wampserver address is //localhost/testsite/ . (the live site is just the domain name).

So that I dont have to hardcode "/testsite/" into my test urls, how can I use my local .htaccess file to use the /testsite/ area? (testsite is the apache alias)

My files are all in the root folder and called page1.php, page2.php, index.php etc. however when I link to page2 it fails because its calling the the relative path to the server ie. just //localhost/page2.php not the expected //localhost/testsite/page2.php

I've tried several htaccess rules but they just try and make apache look in a /testsite/ subfolder for page2.php instead of root.

Should I be using htaccess for this? If so what should the rules be. If not what is the best way to accomplish this?

Thanks in advance

Upvotes: 3

Views: 3065

Answers (1)

anubhava
anubhava

Reputation: 784878

You can have this code in localhost .htaccess:

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/testsite/ [NC]
RewriteRule ^(.*)$ /testsite/$1 [L,NC,R=301]

Upvotes: 3

Related Questions