mod 重写重定向而不改变查询字符串

mod 重写重定向而不改变查询字符串

我需要将某些特定 URL 重定向到另一个控制器。我在 .htaccess 中有以下规则,例如:

RewriteEngine On
RewriteBase /

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

我没有得到的是重定向而不改变用户在浏览器中看到的 URL(必须是潜水/哥斯达黎加-cr)我尝试了 QSA 和 PT 选项,但都没有用。

遵循此规则后,我有以下几点:

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]

也许其中另一条规则会产生影响,但我认为放置 [L] 标志就可以完成重写,对吗?

答案1

R 标志表示重写应作为重定向发送,从而在用户的浏览器行中显示新的 URL。只需将其删除即可。如果您只需要这样做,那么 QSA 和 PT 对您来说都没什么用。

相关内容