Search code examples
apache.htaccessmod-rewritedynamic-url

APACHE Mod Rewrite - Dynamic URLs to Semantic URLs


I have a little web app based on Google Maps. I have URLs like this:

http://www.example.com/web.php?u=olives-restaurante-de-ensaladas-en-margarita

and I want to have exactly this:

http://www.example.com/web/olives-restaurante-de-ensaladas-en-margarita

So I want to convert my parametric dynamic URLs into semantic URLs

How can I achieve this?!

I have tried to put the following code on my .htaccess

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^web/([A-Z0-9]+)/$ web.php?u=$1

But sadly, when I try to access http://www.example.com/web/olives-restaurante-de-ensaladas-en-margarita it redirects me to 404 page.

What I'm doing wrong?


Solution

  • RewriteRule ^web/([A-Z0-9]+)/$ web.php?u=$1
    
    http://www.ubikate.com.ve/web/olives-restaurante-de-ensaladas-en-margarita
    

    Your RewriteRule pattern (^web/([A-Z0-9]+)/$) does not allow hyphens, enforces a trailing slash and only matches uppercase letters, so this won't match the URL you are requesting.

    Try something like the following instead:

    RewriteRule ^web/([\w-]+)$ web.php?u=$1 [L]
    

    The \w is a shorthand character class that is equivalent to [a-zA-Z0-9_].