[Solved]Htaccess to get ride of php?u= doesn't work on localhost

Hi, I put in

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/?$ profile.php?u=$1

in my .htaccess to rewrite the profile.php?u=username to just username.

This works fine on the website but in the localhost the address resolves to "/Users//Sites/mysite/profile.php?u=username"*

Can I find something that works for both the website and localhost?

Thanks!

Solution:
The trick is add conditional rewrite:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^localhost
RewriteRule ^([a-zA-Z0-9_-]+)/?$ http://%{HTTP_REFERER}/~username/mysite/profile.php?u=$1
RewriteCond %{HTTP_HOST} !^localhost
RewriteRule ^([a-zA-Z0-9_-]+)/?$ profile.php?u=$1

The htaccess code you showed doesn’t explain the behavior you’re describing. Is this your whole htaccess? Can we see the rest?

Hi Jeff, this is the whole .htaccess at the moment. If I use it on my website for example, it rewrites the word after the root address that consists of letters and numbers to “profile.php?u=$word”

For example, when I type in “http://www.fuchairs.com/user” in the address bar it brings me to “http://www.fuchairs.com/profile?u=user

I fixed it!

The trick is add conditional rewrite:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^localhost
RewriteRule ^([a-zA-Z0-9_-]+)/?$ http://%{HTTP_REFERER}/~username/mysite/profile.php?u=$1
RewriteCond %{HTTP_HOST} !^localhost
RewriteRule ^([a-zA-Z0-9_-]+)/?$ profile.php?u=$1

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