[SOLVED] Advanced mod_rewrite usage

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
vincentvega
New Member
New Member
Posts: 3
Joined: Sat Nov 29, 2008 3:29 pm

[SOLVED] Advanced mod_rewrite usage

Post by vincentvega »

Hi all,

Since a short time I'm using CMS Made Simple (and I really love it), but unfortunately I came across a problem while using mod_rewrite.

I wrote a 'special' page called news-item which will fetch a remote news-item from an XML feed. To use it I pass ?news_id=23 to it so the script knows which news article to fetch. This is all working great, but now I want to use SEO friendly URLs (I already use it for the 'normal' pages).

What I want is to translate http://www.mysite.com/news-item/23/This is the title/ to http://www.mysite.com/index.php?page=ne ... news_id=23

So I altered the .htaccess file to look like this:

RewriteRule ^news-item/(.+)/(.+)$ index.php?page=news-item&news_id=$1&news_title=$2 [QSA]
RewriteRule ^news-item/(.+)/$ index.php?page=news-item&news_id=$1 [QSA]
RewriteRule ^news-item/(.+)$ index.php?page=news-item&news_id=$1 [QSA]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

However, this breaks the other pages (especially http://www.mysite.com/ which returns a 404).

Does anyone know how to fix this?

Thanks in advance for your time!

Yours Sincerely,
Vincent
Last edited by vincentvega on Wed Dec 03, 2008 4:00 pm, edited 1 time in total.
vincentvega
New Member
New Member
Posts: 3
Joined: Sat Nov 29, 2008 3:29 pm

Re: Advanced mod_rewrite usage

Post by vincentvega »

Fixed. I had to add rewrite conditions to all of the lines.
Post Reply

Return to “Developers Discussion”