.htacess not working on localhost

I am using localhost:8086 as my output port. (with PHP 5.5 Apache 2.4 on windows 7)

I want to rewrite
‘localhost:8086/username’ using .htaccess

I tried running the following code in the .htacess file but it does NOT work.

RewriteEngine On

RewriteCond %{HTTP_HOST} !^localhost:8086
RewriteRule ^([a-zA-Z0-9_-]+)/?$ profile.php?u=$1

I am new to .htaccess… any help would be highly appreciated.


Very quickly, you must enable mod_rewrite on your test server. Then, if NOT localhost, try to match everything (except the dot character) with or without a trailing slash and redirect to profile?

Please have a thorough read of the mod_rewrite tutorial at http://dk.co.nz/seo for setup directions and learning how to write effective mod_rewrite code (with many real world examples).



Thanks so much dklynn!



I’m so glad that it helped!



For the benefit of someone else with the same problem, in addition to enabling mod_rewrite (the command sudo a2enmod rewrite should work, on Linux), you also have to open up the file where you’ve defined your VirtualHost (by default, it’s /etc/apache2/sites-available/default) and then make sure your value for ‘AllowOverride’ is ‘All’.

Basically, you should have a line that reads:
AllowOverride All

Once you make the edit, make sure you reload/restart Apache.

What this does is, it tells Apache that it’s ok to allow users to use any directive in their .htaccess file to override the default Apache settings.

If the ‘AllowOverride’ is set to ‘None’, then your rules in .htaccess won’t work.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.