change news/page/2 to news.php?p=2

New to mod_rewrite? This is a good place to start.

change news/page/2 to news.php?p=2

Postby ash » Tue Jul 07, 2009 2:10 pm

Hi there,

I am having a biggggg problem with this one and have been trying to fix it for some time. Any help on this will be most appreciated.

I need to change
http://www.example.com/News/Page/2

to
http://www.example.com/news.php?p=2

this is my .htaccess file

Code: Select all
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^News$ /news.php [NC,L]
RewriteRule ^News/Page/([^/]+)$ /news.php?p=$1 [NC,QSA,L]


It works... however the base url of the site is changing to:
http://www.examples/News/Page/

breaking a few images that have relative links as they are outside the document root - eg "../img.gif"

Any ideas how this can be fixed?

Many thanks in advance...
ash
 
Posts: 3
Joined: Thu Jun 18, 2009 7:25 am

Postby richardk » Wed Jul 08, 2009 8:35 am

FAQ: Relative paths to images, JavaScript, CSS and other external/linked files are broken. Add the HTML <base> element to your pages.

Cleaned up mod_rewrite
Code: Select all
Options +FollowSymLinks -MultiViews

RewriteEngine On

RewriteRule ^news$               /news.php      [NC,QSA,L]
RewriteRule ^news/page/([0-9]+)$ /news.php?p=$1 [NC,QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: Google [Bot] and 120 guests

cron