Solved

Basics to be followed before using mod_rewrite?!

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
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 …
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: …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

24 Experts available now in Live!

Get 1:1 Help Now