Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Basics to be followed before using mod_rewrite?!

Posted on 2006-06-26
3
Medium Priority
?
208 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 1000 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 1000 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 1000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

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 …
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses
Course of the Month8 days, 13 hours left to enroll

598 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