aarc
aarc

Reputation: 15

automatic rewrite URLs .htaccess

I need to clean url for my web site. The structure is like this :

example.com/home

inside the home folder I have:

index.php 
ambiente.php
.htaccess

This is my .htaccess code:

Options +FollowSymLinks -MultiViews 
RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+ambiente\.php\?ambiente=([^\s&]+) [NC] 
RewriteRule ^ ambiente/%1? [R=301,L]

RewriteRule ^ambiente/([^/]+)/?$ ambiente.php?ambiente=$1 [L,QSA]

I would like the file did this:

example.com/home/ambiente.php?ambiente=living

example.com/home/ambiente/living

The problem is that the URLs are not automatically rewritten.

If I click on the ambiente.php?ambiente=living link in the index file, in the address bar I find example.com/home/ambiente.php?ambiente=living.

If I write in the address bar: http://example.com/home/ambiente/living, it works properly!

How can I solve this?

Upvotes: 1

Views: 60

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

Your Rewritecondition matches /ambiente.php?ambiente=foobar but it does not match the orignal uri /home/ambiente.php?ambiente=foobar Replace your first rewriteRule with the following

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+home/ambiente\.php\?ambiente=([^\s&]+) [NC]
RewriteRule ^  /home/ambiente/%1? [R=301,L]

Upvotes: 1

Related Questions