Redirection sans paramètres dans l'URL

WRInaute accro
PHP:
<span class="syntaxdefault"></span><span class="syntaxkeyword"><?</span><span class="syntaxdefault">php<br /></span><span class="syntaxkeyword">if&nbsp;(!empty(</span><span class="syntaxdefault">$_GET</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'id'</span><span class="syntaxkeyword">])&nbsp;&&&nbsp;</span><span class="syntaxdefault">$_GET</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'id'</span><span class="syntaxkeyword">]&nbsp;===&nbsp;</span><span class="syntaxstring">'des-mots-qui-changent'</span><span class="syntaxkeyword">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">header</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Status:&nbsp;301&nbsp;Moved&nbsp;Permanently"</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">false</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">301</span><span class="syntaxkeyword">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">header</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Location:&nbsp;http://www.example.com/"</span><span class="syntaxkeyword">);<br />&nbsp;&nbsp;&nbsp;&nbsp;exit();<br />}&nbsp;</span><span class="syntaxdefault"></span>
 
WRInaute accro
Code:
RewriteCond %{REQUEST_URI}  ^/$
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^(.*)$ http://www.example.com? [R=301,L,NC]
 
WRInaute discret
Bonjour,

spout a dit:
PHP:
<span class="syntaxdefault"></span><span class="syntaxkeyword"><?</span><span class="syntaxdefault">php<br />if </span><span class="syntaxkeyword">(!empty(</span><span class="syntaxdefault">$_GET</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'id'</span><span class="syntaxkeyword">])</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&&</span><span class="syntaxdefault"> $_GET</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'id'</span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">===</span><span class="syntaxdefault"> </span><span class="syntaxstring">'des-mots-qui-changent'</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault">    header</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Status: 301 Moved Permanently"</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> false</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 301</span><span class="syntaxkeyword">);<br /></span><span class="syntaxdefault">    header</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Location: http://www.example.com/"</span><span class="syntaxkeyword">);<br /></span><span class="syntaxdefault">    exit</span><span class="syntaxkeyword">();<br />}</span><span class="syntaxdefault"></span>

J'ai oublié de préciser que je redirige via .htaccess et que "des-mots-qui-changent" va changer :)

UsagiYojimbo a dit:
Code:
RewriteCond %{REQUEST_URI}  ^/$
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^(.*)$ http://www.example.com? [R=301,L,NC]

Merci ça semble être bon pour un id numérique mais l'id sera sous forme de lettres donc il ne me reste plus qu'à trouver la regex qui convient.

EDIT : la regex qui m'intéresse : a-zA-Z0-9._-

Madrileño a dit:

Merci pour vos réponses, toujours au top.

Cordialement,
Bonne fin de journée.
 
Discussions similaires
Haut