Solved

Basics to be followed before using mod_rewrite?!

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

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…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now