homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

.htaccess - How to get it to work on localhost too!

 11:09 am on Feb 17, 2010 (gmt 0)

Thanks mainly to others on this forum, I've managed to set up a .htaccess file on my live site.

However regardless of what I do, I just can't seem to adapt it in order to get it working on my test site.

My test site takes the form:
http://localhost/www.example.co.uk (its path is C:\xampp\htdocs\www.example.co.uk )

The live .htaccess is:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.example\.co\.uk)?$
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://www.example.co.uk/$1/ [R=301,L]
RewriteCond %{REQUEST_URI} !\.(jpg|jpeg|gif|js|css|class|png)$ [NC]
RewriteCond %{REQUEST_URI} !^/(category/index\.php$|index\.php$|contact-us/|contact-us/|about-us/|terms-and-conditions/|privacy-policy/|feedback/) [NC]
RewriteRule ^.+$ /category/index.php [L]

Can anyone suggest how I adapt the .htaccess so that it will work for my localhost test site?


[edited by: jdMorgan at 1:48 pm (utc) on Feb 17, 2010]
[edit reason] Please use example.com *only* [/edit]



 11:26 am on Feb 17, 2010 (gmt 0)

First to admit my .htaccess is pretty lightweight, but it seems that .htaccess on a development machine is not going to work the same way... there is no outside access... and if there is... why? (Defeats of the purpose of development systems!)


 11:38 am on Feb 17, 2010 (gmt 0)


I want to replicate the sites functionality as closely as possible on the development/test site, in order to spot any mistakes before making it live.


 12:25 pm on Feb 17, 2010 (gmt 0)

.. b0rk

[edited by: g1smd at 12:31 pm (utc) on Feb 17, 2010]


 12:30 pm on Feb 17, 2010 (gmt 0)

I add an optional "dev." after the "www." in the domain canonicalisation rules.

I edit the HOSTS file on my PC to make www.dev.domain.com resolve to the test server's IP.

The Apache Config on the dev server is setup to handle (www.)dev.domaon.com requests.

I now have two sites, dev and www, hosted in different places, but dev is not 'world accessible'.


 1:33 pm on Feb 17, 2010 (gmt 0)

I must be dense as a post. How is that going to work? Dev machines do NOT talk to the world (or shouldn't) and any .htaccess has nothing to work with.


And if it does work with the world what are the implications with B, G, and Y? Seems to me //local is just that. Serious question. Follow up: I tried that xxamp setup and it worked... then worked me on the backend correcting links, etc. Easier for this old fart to just do it in Homesite and post it correct the first time around...


 1:57 pm on Feb 17, 2010 (gmt 0)

The order of the first and second rule need to be reversed. Otherwise, a request for a no-trailing-slash URL-path from the non-www domain will invoke two back-to-back redirects.

With an eye toward efficiency, the function of the RewriteCond in your currently-second rule could be "rolled into" the RewriteRule, simply by removing the leading slash from the pattern and -keeping the surrounding parentheses- using it to replace the RewriteRule's pattern.

The Hosts file set-up g1smd described is for local development where the dev server is not to be world-accessible. If the localhost is accessed locally via HTTP, then Apache and .htaccess will be invoked as it would be on a 'public' server. If your dev server is to be publicly-accessible (in the sense of at least *some* people/agents being able to work on it), then you would define the "dev" subdomain in your usual DNS zone file, rather than in the local machine's Hosts file.



 2:12 pm on Feb 17, 2010 (gmt 0)

Jim, three paragraphs reminds us why you are ghod in these things. Did the eye blinky-blink thing several times and included the smack in the forehead. Thank you--and to g1smd too, for revealations xamp local. Thanks.

Meanwhile I'll do it the other way, avoiding errors in the first place and having no need for redirects. I like KISS best. Sometimes thought is better than fast...


 3:39 pm on Feb 18, 2010 (gmt 0)

Thanks everyone for your help, its appreciated :)


 10:31 am on Feb 21, 2010 (gmt 0)

ok if ur running under window with apache configuration , do as following:
I record the steps here so that it can help those who want to enable .htaccess and url rewriting in Apache for Windows and also for my own reference in future.

1. Make sure you have setup apache and php correctly. Make sure that you can run php scripts without any problem.

2. Use notepad to open httpd.conf config file. Make use the line "LoadModule rewrite_module modules/mod_rewrite.so" is un-commented.

3. Under "<directory #*$!></directory>" section, change the line "AllowOverride None" to "AllowOverride All".

4. Change the line "AccessFileName .htaccess" to "AccessFileName htaccess". This is because in Windows, we can't have a file with filename that starts with a dot.

5. Save the changed file and restart Apache Windows Service. You can then use the file htaccess to process your url rewritting.

Hope this will help u

- Rajendra Pondel


 3:45 pm on Feb 22, 2010 (gmt 0)

@Rajendra -- This is because in Windows, we can't have a file with filename that starts with a dot. --

Only if you try to create/rename/save-as a file as .htaccess via Windows itself.

I use Eclipse as IDE, and I could create .anything


 2:47 am on Feb 25, 2010 (gmt 0)

@blend27, yeah you are right that we just can't rename, name a file with dot. You are also right that we can just copy the file and save it, but Apache comes with the power of naming the file which we can use as .htaccess, so why don't just use that power?

This configuration works best in my development pc, and that's what I wanted to be done.


- Rajenra Pondel

[edited by: jdMorgan at 4:04 am (utc) on Feb 25, 2010]
[edit reason] Edited 'Leet' spelling for all of our international readers. [/edit]

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved