.htaccess RewriteRule doubt

Dear Expert:

I have xampp for Windos installed locally. I have a web site which is using URLs such as:


I want this URL look like:


I have read something about .htaccess file and RewriteRule, so I have added this line to my actual .htaccess file to accomplish this:

RewriteRUle ^/ad/es/Barcelona$ /ad/index.php?option=com_are&view=listado&Itemid=17&lang=es [L]

After this, old URL is still working and new URL (/ad/es/Barcelona) doesn't work (it gets a 404: component not found).

What I'm doing wrong ?

Thank you.
LVL 15
Who is Participating?
Yes, per: http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule

When parsing an .htaccess (directory) based rule Apache first removes the RewritePrefix from the start of the URL path of the requested object, and this prefix is always non null and ends in a a "/", see:

* When using the rewrite engine in .htaccess files the per-directory prefix (which always is the same for a specific directory) is automatically removed for the RewriteRule pattern matching and automatically added after any relative (not starting with a slash or protocol name) substitution encounters the end of a rule set. See the RewriteBase directive for more information regarding what prefix will be added back to relative substitions.
* ....
* The removed prefix always ends with a slash, meaning the matching occurs against a string which never has a leading slash. Therefore, a Pattern with ^/ never matches in per-directory context.

Open in new window

If your rule is in a .htaccess file rather than the httpd.conf you need to remove the leading / e.g.

RewriteEngine On
RewriteBase /
RewriteRule ^ad/es/Barcelona$     /ad/index.php?option=com_are&view=listado&Itemid=17&lang=es [L]

Open in new window

gplanaAuthor Commented:
Wow, it worked without the leading /

Can you tell me why I cannot put a leading / ?
gplanaAuthor Commented:
Excellent. Thank you.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.