.htaccessurlhttp-redirecturl-rewritingaddress-bar

URL rewriting without redirect


I have a couple of directives which should redirect the user to the right path:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ user?user=$1 [QSA]

So that writing www.mywebsite.com/myprofile it displays www.mywebsite.com/user?user=myprofile

It works properly, but it redirects to that URL.

What I would like is that my browser displayed www.mywebsite.com/user?user=myprofile (which is an existing folder on my server), but still showed www.mywebsite.com/myprofile on the address bar, which is the way many websites (as far as I know) create your own profile page.

How is it possible?


Solution

  • you could try just as this:

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^/]+)$ user/?user=$1 [QSA]
    

    or

    RewriteRule ^([^/]+)$ user/index.php?user=$1 [QSA]
    

    With the slash added, the URL is not redirected by only rewritten.