Setting Up RewriteRules for Profile and Tags

user-pic
Vote 1  

Filed:

 
I am adding .htaccess RewriteRules for all the domains we have so we have pretty clean URLs like this one:

http://bgviewsnetwork.com/profile/meancode

That is done by doing this:

RewriteEngine on
RewriteRule ^profile/(.*)$ /mt/mt-cp.cgi?__mode=view&blog_id=49&username=$1 [P,L]

Add a new RewriteRule for each domain you have. Just change the BlogID. Note I am not making a /profile/ RewriteRule for each blog, just one per domain. This also makes the profile_view_url template variable of no use anymore.  Now, to modify the Entry Metadata template module, use this for your link:

<a href="/profile/<mt:EntryAuthorUsername>"><$mt:EntryAuthorDisplayName$></a>

Next on the list of pretty looking URLs are tags. I have both of these changes live on the Sports Blog. It will be live on every blog once I get the RewriteRules done, of which there are a lot - one for each blog in the system, no matter the domain. So now we have URLs such as this:

http://bgnewssports.com/tag/curtmiller

That is done by doing this:

RewriteEngine on
RewriteRule ^dev/tag/(.*)$ /mt/mt-search.fcgi?blog_id=41&tag=$1 [P,L]
RewriteRule ^tag/(.*)$ /mt/mt-search.fcgi?blog_id=49&tag=$1 [P,L]

Add a new RewriteRule for each blog you have. Just change the BlogID and path. Now, to modify the Tag Cloud widget, use this for your link:

<a href="<$mt:BlogURL$>tag/<$mt:TagName normalize="1"$>" rel="tag"><$mt:TagName$></a>

It is worth noting that even tags that have spaces, such as "movable type" or "curt miller" work with the normalize attribute (which takes out spaces). Pretty slick.

Email to a friend

6 Comments

| Leave a comment

Thanks for posting this!

How do you handle spaces in the username? Most of the time the redirect works, except when the user has a space in their name like my%20name

Not sure how to fix this?

You mean to tell me that Movable Type allows spaces in usernames? Really? Well honestly I understand that if it can be broken, people will break it. But I have to ask the dumb question: Why would a person use a space in a username?

Philosophy out of the way, I am pretty sure there is no way to "fix" things with a space in the username, besides a public flogging.

I didn't know it was possible to make a username with a space. I don't have any users who have spaces in usernames. I will have to modify my Registration template to add a warning about that, so thanks for bringing it to my attention.

You may want to see if normalize="1" works in the tag. Worth a shot.

Well my users are the younger crowd so they do goofy things like that. I just noticed it. I'll try out your suggestion and see if it works.

Nope it didn't work. I think I'll just have to tell users not use spaces in the username from now on! That'll fix it! (Or strange characters for that matter!)

I appreciate the informative entry you share in your posts. I’ll bookmark your website and have my friends check up here often. I’m quite certain they will discover a lot of fresh stuff in your site than anybody else!

Anonymous comments are always moderated, please sign in and join the discussion. Create an account for a user profile and community features. Please read our comments policy.

Leave a comment

Poll

Do you like the toolbar at the bottom of this blog?

View results

View & Download PDF


View our support community!

About This Blog

Ken Edwards (and hopefully other project members) will be blogging here — a place to keep up on what is happening on the BG Views project. You will find bits of code, project updates, and random technical information aimed at confusing the hell out of you. More »

Subscriptions

Mobile Edition

Mobile EditionAccess the BG Views Developer Blog on your iPhone or other mobile device. Read more about our mobile site »
Powered by Movable Type 4.34-en

 

Also powered by:

  • Caffeine (Dr. Pepper)
  • Cup Cakes (Hostess)
  • Pizza (Pisanello's)