Web Hosting Forum | Lunarpages
News: October 6, 2008 - Submit Your Site for the October 2008 Site of the Month!
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 15, 2008, 04:19:59 PM


Login with username, password and session length


Pages: [1]   Go Down
  Print  
Author Topic: .htaccess for Search Engine Friendly URL Glitch  (Read 798 times)
lynncrystal
Pong! (the videogame) Master
*****
Offline Offline

Posts: 26


WWW
« on: March 08, 2007, 02:26:28 PM »

Hi everyone,

Taking a stab at using mod_rewrite and .htaccess to get search engine friendly URLs and am stuck.  I think it might be easy to solve, but I'm inexperienced with this and can't seem to pinpoint where the problem is and hoping one of you can help me out.

What I would like to do is rewrite this URL: http://www.carnivalofsong.com/bcl/template3.php?page=archive

As this URL:  http://www.carnivalofsong.com/bcl/template3.php/archive

Here is the code in my current .htaccess file:
RewriteEngine on
RewriteRule ^page/([^/\.]+)/?$ template3.php?page=$1 [L]

The problem that I'm having is that, when I type in the URL as I would like it, my page shows up without my stylesheet linked and without any images or other information.    It looks like I'm rewriting everything instead of just the template3.php?page=$1 part. 

The correct URL to one of the images on the page, which appears when the URL is not rewritten, is:
http://www.carnivalofsong.com/bcl/images/logos/nycbigcitylit.jpg

However, when the URL is rewritten, the image doesn't show and the source of the image shows as this: http://www.carnivalofsong.com/bcl/bcl/images/logos/nycbigcitylit.jpg -- the bcl directory is showing twice.  Confused

Any help you can offer would be greatly appreciated!

Thanks,
Lynn
Logged
MrPhil
Quantum Encyclopedia Writer
*****
Offline Offline

Posts: 3402



« Reply #1 on: March 08, 2007, 02:48:37 PM »

You want to have "static" links and search engine references to

http://www.carnivalofsong.com/bcl/template3/archive

which via your .htaccess turns into

http://www.carnivalofsong.com/bcl/template3.php?page=archive

so you can feed your search program or whatever. Right?

Here's your .htaccess entry:

RewriteEngine On
RewriteRule ^bcl/([^/]+)/([^/]+)/?$  /bcl/$1.php?page=$2


Breaking it down: after stripping off the domain name and a /, match bcl/. Then grab everything up to, but not including, the next / and save it as $1. Match a /. Grab everything up to, but not including, any next / and save it as $2. If there's a lone / on the end, match it. End of pattern. Output /bcl/, what was saved in $1, .php?page=, and what was saved in $2.

You can adjust this to match anything, so long as you understand how it works. Generally it will require a fixed number of fields (between /s). You just can't start matching somewhere down the line at 'page' or whatever.
Logged

lynncrystal
Pong! (the videogame) Master
*****
Offline Offline

Posts: 26


WWW
« Reply #2 on: March 09, 2007, 01:11:46 PM »

Hey MrPhil,

Thanks so much for taking the time to answer my question.  I appreciate you breaking it down for me like you did -- I see my basic concept of the whole thing was a little off, to say the least!

I'm going to give this a try.  Thanks again!

Lynn
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.6 | SMF © 2006-2008, Simple Machines LLC

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM