Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
htaccess and redirecting changed URLS
I’m overhauling a blog of mine, and in the process I would like to be able to change the permalink scheme
For example, under the existing scheme I have lots of entries thus: http://mydomain.com/blog/articlenumber/articlename.
In the new version, I would like to have http://mydomain.com/article/articlename. – so change the section, and drop the article number from the permalink scheme.
I know how to make those changes within the TxP setup and have done so in a dev version of the site, but I wonder if it’s possible to have the old URL scheme automatically redirect to the new one using htacess?
I suspect I will have to keep the article number, but is it possible to use htacces to change the ‘blog’ part of the URL to ‘article’? If so, how?
Thanks!
Last edited by NeilA (2007-08-12 23:49:03)
Offline
Re: htaccess and redirecting changed URLS
Neil,
try to add this line to your .htaccess
file, just above Textpattern’s own RewriteRules starting with RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteRule ^blog/[0-9]*/(.*) http://mydomain.com/article/$1 [R=301,L]
This would inform any user agent, browser, or crawler that your previous URLs have permanently moved to their new location.
Offline
Re: htaccess and redirecting changed URLS
Robert,
You’re a legend! I won’t pretend I understand that line, but it works a treat. Thanks very much.
Cheers
Offline
Re: htaccess and redirecting changed URLS
Well, as they say: mod_rewrite is Apache’s Swiss army knife – it helps a lot, and it potentially hurts a lot (especially inside one’s head).
As a little teaser on how to understand this line, I’ll try to break it into its various parts:
RewriteRule
: This keyword introduces the rule^blog/
: Match any incoming URL which starts with “blog/”[0-9]*/
: Match characters from the set of 0 to 9 (i.e. all digits), even repeatedly as designated by the asterisk, plus a subsequent slash(.*)
: Match any character (.
), repeated at will (*
), and keep that matched text in an internal memory (that’s indicated by the paratheses). This is the very last part of the URL, the article’s slug.
So, this is the condition the incoming URL has to fulfill to get stuffed into the rewrite magic-o-mat. And what shall the outcome of this be?
http://mydomain.com/article/
: Take this literally.$1
: Retrieve the contents of the first store we put there during the condition processing above, i.e. the article slug.[R=301,L]
: Redirect to the newly computed URl by sending it to the visitor’s browser with a HTTP response code of301 Moved permanently
. Do not process any subsequent rules, this is theL
ast.
Now, you could probably imagine what a great pile of satisfaction stems from building a working rewrite rule :))
Offline
Re: htaccess and redirecting changed URLS
Hey, I can actually follow the flow/logic of that Robert.
The syntax is new to me, but you explain it well…
Thanks again
Offline
Pages: 1