ainodoramaaa 2
ainodoramaaa 2

Reputation: 11

the right way redirect url using .htaccess

what is the right way to redirect page using .htaccess?

for ex i want to redirect myweb.com/dorama/901110204/todome-no-kiss--paralel to myweb.com/dorama/1101071510/todome-no-kiss--parallel

but when i try to access old link, link direct to myweb.com/dorama/1101071510/todome-no-kiss--parallel?cat=dorama&idp=901110204&post=todome-no-kiss--paralel

my full .htaccess file

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

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

    #Redirect Dead Link
    Redirect 301 /dorama/901110204/todome-no-kiss--paralel http://www.piratefiles.org/dorama/1101071510/todome-no-kiss--parallel
    Redirect 301 /dorama/601181905/life-as-a-girl http://www.piratefiles.org/dorama/1101072233/life-as-a-girl
    Redirect 301 /dorama/801130021/todome-no-kiss http://www.piratefiles.org/dorama/1101071405/todome-no-kiss

    RewriteRule ^([A-Za-z]+)/([0-9]+)/([\w-]+)/?$    view.php?cat=$1&idp=$2&post=$3&%{QUERY_STRING}   [NC,L]
    RewriteRule ^category/([\w-]+)/?$ category.php?cat=$1&%{QUERY_STRING}   [NC,L]

    # To externally redirect /dir/abc.php to /dir/abc
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?] [NC]
    RewriteRule ^ /%1 [R=301,L,NE]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.+?)/?$ $1.php [QSA,NC,L]

</IfModule>

ErrorDocument 404 http://www.piratefiles.org/404.php

Upvotes: 0

Views: 80

Answers (1)

Rich Bowen
Rich Bowen

Reputation: 5892

RewriteRule directives "run" before Redirect ones do. Thus, if you want to force the redirections to run in a particular order, you need to convert them all to Rewrite directives.

Replace the three Redirect directives with:

RewriteRule ^dorama/(\d+)/(todome-no-kiss--paralel|life-as-a-girl|todome-no-kiss)$ http://www.piratefiles.org/$1/$2 [R=301]

Tweak as necessary, but that's the reason it's failing, and a proposed solution.

(Also, standard note here: If you have access to your main server config, .htaccess files should be avoided whenever possible. .htaccess files are for people that don't have access to the main config.)

Upvotes: 1

Related Questions