Solved

Basics to be followed before using mod_rewrite?!

Posted on 2006-06-26
3
205 Views
Last Modified: 2010-03-04
I would like to know what are the basics needs to be followed before using mod_rewrite.

1) i am using php and basically link images and script using relative path. example: src='../images/image1.gif'

2)i am going to use mod_rewrite to show my links like this
www.site.com/article/news/21

please give me the basic ideas to make it work. I had started using this but have some problem if i use relative path...

Any advice suggesstion links infromation welcome. :)


0
Comment
Question by:str_kani
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
CraigHarris earned 250 total points
ID: 16996275
The links given out from your PHP scripts need to account for the rewriting, as they will be rewritten unless you add a RewriteCond that makes exceptions for them.

Remember, the browser has no idea about where the files are inside the server, it only knows about the URL it "sees", e.g. www.example.com/article/news/21 -- you must make all your links use this format, if you want relative links to work. It won't be able to decipher a relative URL from www.example.com/Articles/MyNewsScript.php?param=21&type=news if the URL it's using is www.example.com/article/news/21

Relative paths can in cases make code more managable and more portable - BUT only within modules .... using relative URLs accross modules is a recipe for disaster, as you are now finding out. -- if you can make everything semi-absolute (relative to root) e.g. "/images/image1.gif" then it is easy to skip rewriting these.
0
 
LVL 16

Assisted Solution

by:xDamox
xDamox earned 250 total points
ID: 17001829
Hi,

You could try the following in a .htaccess file:

RewriteEngine On

RewriteRule ^article/news/([0-9])   /path/to/script.php?$1
0
 
LVL 7

Assisted Solution

by:CraigHarris
CraigHarris earned 250 total points
ID: 17002229
xDamox, that works fine if everything uses the "new" link style, but that doesn't account for relative links from old system
If /article/news/21/ contains a link to ../images/image1.gif
The browser will try to load /article/news/images/image1.gif -- which may or may not be the correct file.

Actually it should be:

RewriteEngine On
RewriteRule ^/article/news/([0-9]+) /path/to/whereever.php?id=$1


or maybe:

RewriteRule ^/article/news/([0-9]+) /path/to/whereever.php?id=$1&type=news

or generically:

RewriteRule ^/article/([A-Za-z]+)/([0-9]+) /path/to/whereever.php?type=$1&id=$2

depending on script structure etc etc
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question