Author Topic: Redirect permanent does not work?! Why?  (Read 11521 times)

0 Members and 1 Guest are viewing this topic.

Offline wflorian

  • Newbie
  • *
  • Posts: 47
    • View Profile
Redirect permanent does not work?! Why?
« on: December 26, 2008, 11:17:25 PM »
Hey,

I am trying to redirect some pages. I have several pages with the the following url design:

/index.php?template=somepage

I changed this design with a RewriteRule to /somepage.html

Right now the page is reachable through /index.php?template=somepage and /somepage.html
This would mean DuplicateContent. So I would like to redirect the /index.php?template=somepage pages to the new ones.

I tried the following code in my htaccess:

Redirect permanent /index.php?template=somepage http://www.XXXX.com/somepage.htm

But actually it does not work at all. Not even an error message. Does anybody know why? Any suggestions what changes I should make in my .htaccess file?

Thanks in advance.

Regards.
Florian


Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Redirect permanent does not work?! Why?
« Reply #1 on: December 27, 2008, 01:02:44 AM »
Code: [Select]
RewriteCond %{REQUEST_URI} index\.php$
RewriteCond %{QUERY_STRING} ^((.+)&)?template=([^&]+)&*$ [OR]
RewriteCond %{QUERY_STRING} ^((.+)&)?template=([^&]+)(&.+)$
RewriteRule .* http://www.XXXX.com/%3.html?%2%4 [R=301,L]
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline wflorian

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: Redirect permanent does not work?! Why?
« Reply #2 on: December 27, 2008, 09:17:15 AM »
Hey v@ano,

thanks for your answer. I tried your code. But when using I do get an error message. Unfortunately in the URL field there is the correct /somepage.html URL. I get this error:

ORIGINAL MESSAGE:

Umleitungsschleife   

Die aufgerufene Website leitet die Anfrage so um, dass sie nie beendet werden kann.

Der Verbindungsversuch zur aufgerufenen Adresse wurde abgebrochen. Die aufgerufene Website leitet die Anfrage so um, dass sie nie beendet werden kann.

    * Haben Sie Cookies, die von dieser Website benötigt werden, deaktiviert oder blockiert?
    * HINWEIS: Falls das Akzeptieren von Cookies die Probleme mit der aufgerufenen Adresse nicht behebt, handelt es sich vermutlich um eine Fehlkonfiguration des Servers und nicht um einen Fehler Ihres Computers.

TRANSLATED MESSAGE:

Redirection loop

The requested site directs the request so that they can never be stopped.

The connection attempt to address called was canceled. The requested site directs the request so that they can never be stopped.

     * Do you have cookies from this Web site are needed, disabled or blocked?
     * NOTE: If the acceptance of cookies with the problems of the called address does not resolve, it is probably a misconfiguration of the server and not an error on your computer

Offline wflorian

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: Redirect permanent does not work?! Why?
« Reply #3 on: December 29, 2008, 07:28:02 PM »
No idea anybody?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Redirect permanent does not work?! Why?
« Reply #4 on: December 30, 2008, 07:39:09 AM »
Worked fine on my test site...
please show your entire .htaccess including these changes (you can alter the paths if you wish)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline wflorian

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: Redirect permanent does not work?! Why?
« Reply #5 on: December 30, 2008, 09:47:27 AM »
hey v@ano, thanks for helping me.

here we go:

<code>
ErrorDocument 404 /404.html

RewriteEngine On

RewriteCond %{HTTP_HOST} ^mysite\.de$ [NC]
RewriteRule ^(.*)$ http://www.mysite.de/$1 [L,R=301]

#RewriteBase /is/xxxx/xxxx
RewriteRule ^lightbox\.htm$ lightbox.php?%{QUERY_STRING}
RewriteRule ^lightbox\.([0-9]+)\.htm$ lightbox.php?page=$1&%{QUERY_STRING}

RewriteRule ^search\.htm$ search.php?%{QUERY_STRING}
RewriteRule ^search\.([0-9]+)\.htm$ search.php?page=$1&%{QUERY_STRING}

RewriteRule ^cat\.htm$ categories.php?%{QUERY_STRING}
RewriteRule ^cat([0-9]+)\.([0-9]+)\.htm$ categories.php?cat_id=$1&page=$2&%{QUERY_STRING}
RewriteRule ^cat([0-9]+)\.htm$ categories.php?cat_id=$1&%{QUERY_STRING}

RewriteRule ^img([0-9]+)\.htm$ details.php?image_id=$1&%{QUERY_STRING}
RewriteRule ^img([0-9]+)\.([a-zA-Z0-9]+)\.htm$ details.php?image_id=$1&mode=$2&%{QUERY_STRING}

RewriteRule ^postcard([a-zA-Z0-9]+)\.htm$ postcards.php?postcard_id=$1&%{QUERY_STRING}
RewriteRule ^postcard\.img([0-9]+)\.htm$ postcards.php?image_id=$1&%{QUERY_STRING}

RewriteRule ^([a-zA-Z0-9_-]+)\.htm$ index.php?template=$1&%{QUERY_STRING}

RewriteRule ^sitemap.xml$ google.php
</code>

Offline wflorian

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: Redirect permanent does not work?! Why?
« Reply #6 on: January 05, 2009, 09:54:37 PM »
does the full code help you?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Redirect permanent does not work?! Why?
« Reply #7 on: January 06, 2009, 04:34:48 AM »
I did specify "including these changes" ;)


Any way, try remove
Code: [Select]
RewriteRule ^([a-zA-Z0-9_-]+)\.htm$ index.php?template=$1&%{QUERY_STRING}
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline wflorian

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: Redirect permanent does not work?! Why?
« Reply #8 on: January 06, 2009, 09:39:08 AM »
 :D

well i did remove the line, unfortunately i do get a 404 error page.

when opening a url www.XXXXXXXX.com/index.php?template=somepage I do get redirected to www.XXXXXXXX.com/somepage.htm (I can see the URL in the browser line) but the I do get the 404 error page.

here is the full htaccess with the new code:

Code: [Select]
ErrorDocument 404 /404.html

RewriteEngine On

RewriteCond %{HTTP_HOST} ^XXXXXX\.de$ [NC]
RewriteRule ^(.*)$ http://www.XXXXXX.de/$1 [L,R=301]

#RewriteBase /is/htdocs/XXXXXX
RewriteRule ^lightbox\.htm$ lightbox.php?%{QUERY_STRING}
RewriteRule ^lightbox\.([0-9]+)\.htm$ lightbox.php?page=$1&%{QUERY_STRING}

RewriteRule ^search\.htm$ search.php?%{QUERY_STRING}
RewriteRule ^search\.([0-9]+)\.htm$ search.php?page=$1&%{QUERY_STRING}

RewriteRule ^cat\.htm$ categories.php?%{QUERY_STRING}
RewriteRule ^cat([0-9]+)\.([0-9]+)\.htm$ categories.php?cat_id=$1&page=$2&%{QUERY_STRING}
RewriteRule ^cat([0-9]+)\.htm$ categories.php?cat_id=$1&%{QUERY_STRING}

RewriteRule ^img([0-9]+)\.htm$ details.php?image_id=$1&%{QUERY_STRING}
RewriteRule ^img([0-9]+)\.([a-zA-Z0-9]+)\.htm$ details.php?image_id=$1&mode=$2&%{QUERY_STRING}

RewriteRule ^postcard([a-zA-Z0-9]+)\.htm$ postcards.php?postcard_id=$1&%{QUERY_STRING}
RewriteRule ^postcard\.img([0-9]+)\.htm$ postcards.php?image_id=$1&%{QUERY_STRING}

RewriteCond %{REQUEST_URI} index\.php$
RewriteCond %{QUERY_STRING} ^((.+)&)?template=([^&]+)&*$ [OR]
RewriteCond %{QUERY_STRING} ^((.+)&)?template=([^&]+)(&.+)$
RewriteRule .* http://www.XXXXXX.de/%3.htm?%2%4 [R=301,L]

RewriteRule ^sitemap.xml$ google.php

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Redirect permanent does not work?! Why?
« Reply #9 on: January 06, 2009, 03:53:23 PM »
Finally got it working:
Code: [Select]
RewriteRule ^([a-zA-Z0-9_-]+)\.htm$ index.php?template=$1&rewritten&%{QUERY_STRING} [L]

RewriteCond %{REQUEST_URI} index\.php$
RewriteCond %{QUERY_STRING} !&rewritten&?
RewriteCond %{QUERY_STRING} ^((.+)&)?template=([^&]+)&*$ [OR]
RewriteCond %{QUERY_STRING} ^((.+)&)?template=([^&]+)(&.+)$
RewriteRule .* http://www.XXXXXX.de/%3.htm?%2%4 [R=301,L]
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline wflorian

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: Redirect permanent does not work?! Why?
« Reply #10 on: January 06, 2009, 04:42:09 PM »
THANK YOU v@ano. Works absolutely great! :wink: