.htaccess RewriteRule doubt

Dear Expert:

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

http://localhost/ad/index.php?option=com_are&view=listado&Itemid=17&lang=es

I want this URL look like:

http://localhost/ad/es/Barcelona

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
gplanaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

arober11Commented:
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

0
gplanaAuthor Commented:
Wow, it worked without the leading /

Can you tell me why I cannot put a leading / ?
0
arober11Commented:
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gplanaAuthor Commented:
Excellent. Thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.