Search code examples
.htaccesshttp-redirectmod-rewriteurl-rewritingfriendly-url

User friendly URL for separate folder in website in php


I have a folder (market) in which i have one file called (index.php) The URL is like this :

www.website.com/market/?u=xxx

I want to make a user friendly URL that looks like this:

www.website.com/market/u/xxxx

In .htaccess file I put this code:

# Turn Rewrite Engine On
RewriteEngine on

RewriteRule ^u/([0-9a-zA-Z]+) index.php?u=$1 [NC, L]

I get this response:

**Internal Server Error**
The server encountered an internal error or misconfiguration and was unable to complete your request.

What did I do wrong here?

NB: I put the .htaccess file inside the market folder


Solution

  • Based on your shown samples, could you please try following. Please make sure you clear your browser cache before testing your URLs. You need to rewrite and redirect here as per your need what you are trying is only rewrite that's the reason its not working for you.

    RewriteEngine ON
    RewriteCond %{THE_REQUEST} \s/(market)/\?(u)=([^\s]*)\s [NC]
    RewriteRule ^ http://%{HTTP_HOST}/%1/%2/%3 [R=301]
    RewriteRule ^market/(u)/([0-9a-zA-Z]+)/?$ index.php?$1=$2 [NC,L]