3

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

1 Answer 1

3

You can have this code in localhost .htaccess:

RewriteEngine On RewriteCond %{REQUEST_URI} !^/testsite/ [NC] RewriteRule ^(.*)$ /testsite/$1 [L,NC,R=301] 
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for the quick response, however that creates a double entry result ie //localhost/testsite/testsite/index.php can you explain?
Ok, now the duplicate is gone but get this error - "Firefox has detected that the server is redirecting the request for this address in a way that will never complete."
Doh! ok, the initial load now works with //localhost/testsite/index.php but as soon as I click the link to page2 the url changes to //localhost/page2.php and fails to load the page.
That's the problem. .htaccess should be in c:/wampserver/www/
Can't thank you enough for this. As soon as I moved .htaccess into c:/wampserver/www/, my website worked! Thanks a ton!!!
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.