简体   繁体   English

重写Problen .htaccess重定向301

[英]Rewrite Problen .htaccess Redirect 301

I need put a redirect on a site and a have some problems. 我需要在网站上放置重定向,并且存在一些问题。

I have this original .htccess 我有这个原始的.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. 我输入了最后4行以提供这5页的重定向。

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 但是当我请求该页面时: http : //example.com/sobre-a-personal-evolution

I received this: http://example.com/sobre/?url=sobre-a-personal-evolution 我收到了这个消息: http : //example.com/sobre/?url=sobre-a-personal-evolution

But the correct for me would this one: http:// example.com/sobre/ 但是对我来说正确的方法是: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 : mod_alias/Redirect文档中

Additional path information beyond the matched URL-Path will be appended to the target URL. 匹配的URL-Path之外的其他路径信息将附加到目标URL。

"Additional path information" is somewhat vague, but I assume they are referring to the url parameter. “其他路径信息”有些模糊,但是我认为它们是指url参数。

Now, this should not affect functionality at all, so again I assume that you just don't like how the URL looks. 现在,这根本不影响功能,因此我再次假设您只是不喜欢URL的外观。

However, since you are using mod_rewrite anyway, you can achieve the same effect as Redirect with RewriteRule : 但是,由于无论如何都使用mod_rewrite ,因此可以通过RewriteRule获得与Redirect相同的效果:

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: 您不得将mod_rewrite规则与mod_alias规则混合使用,并在内部重写规则之前保留重定向规则:

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/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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