简体   繁体   中英

Rewrite Problen .htaccess Redirect 301

I need put a redirect on a site and a have some problems.

I have this original .htccess

RewriteEngine on
RewriteCond %{REQUEST_URI} \.json$ [NC]
RewriteRule .* - [F,L]
RewriteRule config/.* - [F,L]
RewriteRule config - [F,L]

RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteRule ^.+$ - [L]

RewriteCond %{QUERY_STRING} ^$ [NC]
RewriteRule ^([^?]+)$ /novo-site/index.php?url
RewriteCond %{QUERY_STRING} ^$ [NC]
RewriteRule ^$ /novo-site/index.php

AddHandler php54-script .php
suPHP_ConfigPath /home/personalglass1/site02/novo-site/

And i put the last 4 lines to provide the redirect for this 5 pages.

The result is this:

RewriteEngine on

RewriteCond %{REQUEST_URI} \.json$ [NC]
RewriteRule .* - [F,L]
RewriteRule config/.* - [F,L]
RewriteRule config - [F,L]

RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteRule ^.+$ - [L]

RewriteCond %{QUERY_STRING} ^$ [NC]
RewriteRule ^([^?]+)$ /novo-site/index.php?url=$1
RewriteCond %{QUERY_STRING} ^$ [NC]
RewriteRule ^$ /novo-site/

AddHandler php54-script .php
suPHP_ConfigPath /home/personalglass1/site02/novo-site/

Redirect 301 /sobre-a-personal-evolution /sobre/
Redirect 301 /fechamento-de-sacadas-e-varandas /produto/envidracamento/
Redirect 301 /revendedores-autorizados /revendedores/
Redirect 301 /entre-em-contato /contato/
Redirect 301 /fotos-de-sacadas-evolution /galerias/

But when i requested the page: http://example.com/sobre-a-personal-evolution

I received this: http://example.com/sobre/?url=sobre-a-personal-evolution

But the correct for me would this one: http:// example.com/sobre/

Is the last one that i need when a request the first.

I tried to some changes but nothing works!

Someone could help me solve this and explain how to this, i need understand how to do this.

Thanks!

From the mod_alias/Redirect documentation :

Additional path information beyond the matched URL-Path will be appended to the target URL.

"Additional path information" is somewhat vague, but I assume they are referring to the url parameter.

Now, this should not affect functionality at all, so again I assume that you just don't like how the URL looks.

However, since you are using mod_rewrite anyway, you can achieve the same effect as Redirect with RewriteRule :

RewriteRule ^/sobre-a-personal-evolution(?:/(.*))?$ /sobre/$1 [R=301,L]

You must not mix mod_rewrite rules with mod_alias rules and keep redirect rules before internal rewrite rules:

RewriteEngine on

RewriteRule \.json$ - [F,L,NC]

RewriteRule config(/|$) - [F,L,NC]

RewriteRule ^sobre-a-personal-evolution /sobre/ [L,NC,R=301]
RewriteRule ^fechamento-de-sacadas-e-varandas /produto/envidracamento/ [L,NC,R=301]
RewriteRule ^revendedores-autorizados /revendedores/ [L,NC,R=301]
RewriteRule ^entre-em-contato /contato/ [L,NC,R=301]
RewriteRule ^fotos-de-sacadas-evolution /galerias/ [L,NC,R=301]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.+)$ /novo-site/index.php?url=$1 [L,QSA]

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^$ /novo-site/ [L]

AddHandler php54-script .php
suPHP_ConfigPath /home/personalglass1/site02/novo-site/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM