簡體   English   中英

重寫Problen .htaccess重定向301

[英]Rewrite Problen .htaccess Redirect 301

我需要在網站上放置重定向,並且存在一些問題。

我有這個原始的.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/

我輸入了最后4行以提供這5頁的重定向。

結果是這樣的:

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/

但是當我請求該頁面時: http : //example.com/sobre-a-personal-evolution

我收到了這個消息: http : //example.com/sobre/?url=sobre-a-personal-evolution

但是對我來說正確的方法是:http:// example.com/sobre/

是第一個請求時我需要的最后一個。

我嘗試了一些更改,但沒有任何效果!

有人可以幫助我解決這個問題並解釋如何做到這一點,我需要了解如何做到這一點。

謝謝!

mod_alias/Redirect文檔中

匹配的URL-Path之外的其他路徑信息將附加到目標URL。

“其他路徑信息”有些模糊,但是我認為它們是指url參數。

現在,這根本不影響功能,因此我再次假設您只是不喜歡URL的外觀。

但是,由於無論如何都使用mod_rewrite ,因此可以通過RewriteRule獲得與Redirect相同的效果:

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

您不得將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