Page 1 of 1
How to implement 301?
Posted: Wed Sep 17, 2008 10:11 pm
by Greyer
Hi everyone,
I have made some changes in my URLs and now want to 301 redirect the old pages to the new ones. I searched around to figure out how exactly to create the 301 rule in the .htaccess file. I tried several syntaxes but neither of them worked and one even crashed the server (500)
Can someone please post a detailed explanation of the 301 redirect rule that works in serendipity (special characters and everything)?
Re: How to implement 301?
Posted: Thu Sep 18, 2008 11:40 am
by garvinhicking
Hi!
Tell us which ones you tried and we can tell you what's wrong about it
Can someone please post a detailed explanation of the 301 redirect rule that works in serendipity (special characters and everything)?
s9y is nothing different/specific than every .htacces RewriteRule, so you can google it up, there are many tutorials about this...
Regards,
Garvin
Posted: Thu Sep 18, 2008 2:33 pm
by Greyer
I tried
Code: Select all
Redirect permanent /index.php?/archives/4-old-url.html /archives/new-url.html
which gave me a 500 error
tried the same code with full URLs - nothing.
Tried
Code: Select all
RewriteRule ^/index.php?/archives/old.html /archives/new.html [R]
--still nothing
Tried the same with full second URL -- nothing
Tried with full URLs on both sides -- nothing...
I am either missing something in the code or I just don't write where I have to.
Can you guys tell me what to write in the .htaccess so I can redirect
mysite.com/index.php?/archives/4-old-url.html to mysite.com/archives/new-url.html
Posted: Thu Sep 18, 2008 4:13 pm
by garvinhicking
Hi!
The first one I have not seen yet, I don't think this is a valid mod_rewrit eRule.
The second one is better, but URLs are matched by everything BEFORE the "?", and "?" is a special character in regular expressions.
Maybe you can try (according to
http://fantomaster.com/faarticles/rewritingurls.txt which you can read through)
Code: Select all
RewriteCond %{QUERY_STRING} ^/archives/old.html$
RewriteRule ^.* /archives/new.html [R]
HTH,
Garvin
Posted: Thu Sep 18, 2008 9:29 pm
by Greyer
still nothing... I can't figure out what goes wrong. I have a hunch it is because of the " /index.php?/ " part of the old URL...
Posted: Thu Sep 18, 2008 10:45 pm
by Greyer
Ok, so I added
Code: Select all
Redirect 301 /archives/old-url.html http://mysite.com/archives/new-url.html
and it DID redirect it to the new URL, but added " ?url=/archive " at the end of the new address. Any ideas how to remove it?
Also, for some reason in could not redirect /index.php?/archives/old-url.html to the new one, and I am pretty sure it has to do with that "?" in the middle.
Posted: Fri Sep 19, 2008 11:16 am
by garvinhicking
Hi!
Yeah, because of that "?" you need to use RewriteCOND and not only RewriteRule...
HTH,
Garvin
Posted: Fri Sep 19, 2008 7:52 pm
by Greyer
I tried everything and the only rule that seems to be working is the Redirect 301 from my previous post, but it only works for URLs without the " index.php?" (URLs which are already rewritten with the functions_permalinks.inc.php file)
I am thinking that somewhere on the road there is something that overrides all the additional RewriteRules I enter and the only thing working is the Redirect 301 rule, but I can't find what it is.
Here is an exact copy of the .htaccess file
Code: Select all
# BEGIN s9y
ErrorDocument 404 /index.php
DirectoryIndex /index.php
php_value session.use_trans_sid 0
php_value register_globals off
RewriteEngine On
RewriteBase /
RewriteRule ^((archives/[0-9a-z\.\_!;,\+\-\%]+\.html)/?) index.php?/$1 [NC,L,QSA]
RewriteRule ^(authors/[0-9a-z\.\_!;,\+\-\%]+) index.php?/$1 [NC,L,QSA]
RewriteRule ^(feeds/categories/[0-9a-z\.\_!;,\+\-\%]+\.rss) index.php?/$1 [NC,L,QSA]
RewriteRule ^(feeds/authors/[0-9a-z\.\_!;,\+\-\%]+\.rss) index.php?/$1 [NC,L,QSA]
RewriteRule ^(categories/[0-9a-z\.\_!;,\+\-\%]+) index.php?/$1 [NC,L,QSA]
RewriteRule ^archives([/A-Za-z0-9]+)\.html index.php?url=/archives/$1.html [NC,L,QSA]
RewriteRule ^([0-9]+)[_\-][0-9a-z_\-]*\.html index.php?url=$1-article.html [L,NC,QSA]
RewriteRule ^feeds/(.*) index.php?url=/feeds/$1 [L,QSA]
RewriteRule ^unsubscribe/(.*)/([0-9]+) index.php?url=/unsubscribe/$1/$2 [L,QSA]
RewriteRule ^approve/(.*)/(.*)/([0-9]+) index.php?url=approve/$1/$2/$3 [L,QSA]
RewriteRule ^delete/(.*)/(.*)/([0-9]+) index.php?url=delete/$1/$2/$3 [L,QSA]
#RewriteRule ^(admin|entries)(/.+)? index.php?url=admin/ [L,QSA]
RewriteRule ^archive/? index.php?url=/archive [L,QSA]
RewriteRule ^(index|atom[0-9]*|rss|b2rss|b2rdf).(rss|rdf|rss2|xml) rss.php?file=$1&ext=$2
RewriteRule ^(plugin|plugin)/(.*) index.php?url=$1/$2 [L,QSA]
RewriteRule ^search/(.*) index.php?url=/search/$1 [L,QSA]
RewriteRule ^comments/(.*) index.php?url=/comments/$1 [L,QSA]
RewriteRule ^(serendipity\.css|serendipity_admin\.css) index.php?url=/$1 [L,QSA]
RewriteRule ^index\.(html?|php.+) index.php?url=index.html [L,QSA]
RewriteRule ^htmlarea/(.*) htmlarea/$1 [L,QSA]
RewriteRule (.*\.html?) index.php?url=/$1 [L,QSA]
<Files *.tpl.php>
deny from all
</Files>
<Files *.tpl>
deny from all
</Files>
<Files *.sql>
deny from all
</Files>
<Files *.inc.php>
deny from all
</Files>
<Files *.db>
deny from all
</Files>
# END s9y
Do you find anything out of the ordinary (the only change I have made is commenting out one of the lines, as I use the /admin.php for somehing else)
Posted: Fri Sep 19, 2008 8:21 pm
by garvinhicking
Hi!
You should definitely put your custom rewriteRules as the first ones. Try to append [L] to its option so that htaccess stops parsing when your own rule is matched.
Regards,
Garvin