Working on one of my current projects, I found myself needing to do some rewrite rules (non www. redirect and pretty URLs being the most prominent). I’ve never done this in my life before so I went looking for tutorials. I got everything working, URLs all snazzy and such. Then I tried to add another rewrite rule that took URLs such as index.php?p=page&sub=subpage and turn them into /page/subpage/, and immediately found myself with no stylesheet and no images. The problem became obvious after I realized that I just told my website to take /css/style.css and try to pull it from index.php?p=css&sub=style.css.
I needed another rule, this is what I wrote:
RewriteBase /
RewriteRule (^css/(.*)$|^images/(.*)$|^scripts/(.*)$) - [L]
All this does is exclude three strings from the rewrite rules that follow: css/* (* being any string, a wildcard), images/* and scripts/*. In essence all I’m doing is telling my rewrite rules to not touch certain folders. If I wanted to exclude certain filetypes (for example, “.jpg”), I could do this:
RewriteBase /
RewriteRule (^files/(.*).jpg$) - [NC]
This would exclude all .jpg files from my rewrite rules. The [NC] directive tells the rule to ignore case (in this case, it’s to make sure that the rule is also applied to .JPG as well). Here’s my full .htaccess file for the project (domain is hidden =P):
RewriteEngine on
RewriteBase /
# Exclude css, images and scripts folders from rules
RewriteRule (^css/(.*)$|^images/(.*)$|^scripts/(.*)$) - [L]
# Redirect non www. to www.
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1
# Pretty URLs
RewriteRule ^(.*)/(.*)/ index.php?p=$1⊂=$2 [L]
RewriteRule ^([^/\.]+)/ index.php?p=$1 [L]
I guess to a lot of people this is a pretty obvious and noobish post, but I’m sure it’ll help some people out. If there’s any obvious errors in there, feel free to point them out. I’m still learning! Enjoy.
I’ve wanted a blog for the longest time but I always get caught up in what a lot of design-oriented people do: I get so caught up in designing my blog that I never end up posting a fucking thing.
I found this blog theme lying around from a few months ago and it’s pretty much complete. I was going to use a free theme just so I could actually have some content on here and eventually I might be motivated to redesign and end up with a blog that looks nice and has things on it, but I managed to one-up that idea and I found a theme that suits the purpose just fine.
So how about that introduction. If you don’t know, I’m Tyler Lemieux, a 19 year old web designer, developer, want-to-be marketer among other things.
I’m starting this blog as a way to keep track and keep in writing my attempts at affiliate marketing. As of today, I’m on my 3rd day of messing around with Adwords (I’m in the negatives, but not by much) and I’m working my way towards learning more about SEO. My current projects are my Guitar Hero tips and guides blog (anchor text!) and a certain project that I won’t be revealing until I know how successful it can be. In my head, the idea seems great and so far researching the niche is telling me that it’s pretty much completely open, but hey, I know jack shit. Maybe I’ll get lucky though, who knows!
Keeping with the “this blog is for…” theme, I’ll also be posting a good bit of design-related stuff since that’s what I know. I’ve been designing for something like 7 or 8 years now so hopefully I have something to provide you. Once I get more into the AM game, I’ll start connecting the two, and I know a lot of you guys will like that.
That’s all for my first post then, I can’t think of anything else to write! Peace out.
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Jan | ||||||
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | 30 | 31 | ||