Solved

Basics to be followed before using mod_rewrite?!

Posted on 2006-06-26
3
206 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

726 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