Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to redirect some specific URLs to another controller. I have this rules in the .htaccess, for example:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} diving/costa-rica-cr$
RewriteRule ^diving/costa-rica-cr$ new/url?id=29&landingact=11 [R,L]

What I'm not getting is redirecting without changins the URL that the user see in the browser (must be diving/costa-rica-cr). I tried with QSA and PT options but none worked.

Afted this rules I have the following:

RewriteCond %{REQUEST_URI} guias/(.*)(\..*){2,}\.php$
RewriteRule ^guias/(.*)(\..*){2,}\.php$ viajes/$1 [R=301,L]

RewriteCond %{REQUEST_URI} guias/(.*)\.(.*)\.php$
RewriteRule ^guias/(.*)\.(.*)\.php$ viajes/$1-${countrymap:$2} [R=301,L]

RewriteCond %{REQUEST_URI} viaje-a/(.*)(\..*){2,}\.php$
RewriteRule ^viaje-a/(.*)(\..*){2,}\.php$ viajes/$1 [R=301,L]

RewriteCond %{REQUEST_URI} viaje-a/(.*)\.(.*)\.php$
RewriteRule ^viaje-a/(.*)\.(.*)\.php$ viajes/$1-${countrymap:$2} [R=301,L]

RewriteCond %{REQUEST_URI} viajes-a-medida/(.*)(\..*){2,}\.php$
RewriteRule ^viajes-a-medida/(.*)(\..*){2,}\.php$ tours/$1 [R=301,L]

RewriteCond %{REQUEST_URI} viajes-a-medida/(.*)\.(.*)\.php$
RewriteRule ^viajes-a-medida/(.*)\.(.*)\.php$ tours/$1-${countrymap:$2} [R=301,L]

RewriteCond %{REQUEST_URI} recomendaciones-viaje/(.*)(\..*){2,}\.php$
RewriteRule ^recomendaciones-viaje/(.*)(\..*){2,}\.php$ visados-y-vacunas/$1 [R=301,L]

RewriteCond %{REQUEST_URI} recomendaciones-viaje/(.*)\.(.*)\.php$
RewriteRule ^recomendaciones-viaje/(.*)\.(.*)\.php$ visados-y-vacunas/$1-${countrymap:$2} [R=301,L]

RewriteCond %{REQUEST_URI} (que-ver-en|como-es|idioma-moneda-horarios|vuelos|hoteles|alquiler-de-coches|fotos-de|viajar-con-ninos|tours|esqui)/(.*)(\..*){2,}\.php$
RewriteRule ^(que-ver-en|como-es|idioma-moneda-horarios|vuelos|hoteles|alquiler-de-coches|fotos-de|viajar-con-ninos|tours|esqui)/(.*)(\..*){2,}\.php$ $1/$2 [R=301,L]

RewriteRule ^(que-ver-en|como-es|idioma-moneda-horarios|vuelos|hoteles|alquiler-de-coches|fotos-de|viajar-con-ninos|tours|esqui)/(.*)\.(.*)\.php$ $1/$2-${countrymap:$3} [R=301,L]

RewriteCond %{REQUEST_URI} !tools/.*
RewriteCond %{REQUEST_URI} !blog/.*
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+php?\ HTTP
RewriteRule ^(.*)\.php$ $1 [R=301,L]

RewriteCond %{REQUEST_URI} !fotos-tours/.*
RewriteCond %{REQUEST_URI} (que-ver-en|como-es|idioma-moneda-horarios|vuelos|hoteles|alquiler-de-coches|fotos-de|viajar-con-ninos|tours|viajes|actividades|cuando-ir|visados-y-vacunas|esqui)/.*
RewriteCond %{REQUEST_URI} !(.*)\.php$
RewriteRule ^(.*)$ $1.php [QSA,L]

RewriteRule ^blog/(.*) public_html/blog/$1 [L]
RewriteRule ^$ %{REQUEST_URI}donde-me-voy/vacaciones [L]
RewriteRule (.*) public_html/$1 [L]

Maybe another one of there rules affect, but I think that putting the [L] flag finishes the rewriting right?

share|improve this question

The R flag means that the rewrite should be sent as a redirect, thus showing the new URL in the user's browser line. Just remove that. Neither QSA nor PT would be useful in your case, if that's all you need to do.

share|improve this answer
Hi, removing the R redirects to homepage (/). I don't know if the fact that the first URL (diving/costa-rica-cr) doesn't exists as a file affects some way. – Sergi Jul 23 '12 at 10:00
Do you have any other rewriterules than the ones you've posted? Or any AliasMatch? – Jenny D Jul 23 '12 at 10:02
I edited the question adding the other rules in the .htaccess – Sergi Jul 23 '12 at 10:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.