Forum Moderators: phranque

Message Too Old, No Replies

URL Rewrite

         

robiq

11:44 am on Dec 17, 2007 (gmt 0)

10+ Year Member



Hi,

I'm pretty new to URL rewriting and am quite stuck as to how to proceed. What I am trying to do is get my site to offer search engine friendly URLs for files and variables.

So if someone enters website/news/articles/newstory1
It redirects to website/news.php/articles/newstory1

Or if its just website/news or website/news/
It redirects to website/news.php

I can get it to do that with the following rules

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([a-z0-9_-]+)+/([a-z09_/-]+)?$ $1.php/$2 [NC,L]
RewriteRule ^([a-z0-9_-]+)+/?$ $1.php [NC,L]

However, only certain pages have their own php page, the rest will be accessing page.php and using the /#*$! to query a database, so in those case something like website/aboutus should redirect to website/page.php/aboutus . This is where I am having the problems. I have got a rule that will do this, but using it overwrites the 2 rules above, so everything is redirected to page.php . The rule is:

RewriteRule ^([a-z0-9_-]+)+.php$ page.php/$1 [NC]

Is there a way, maybe using conditions, that I could get it to perform the top 2 rules, and if they do not result in a file to then use the third rule? I have tried RewriteCond $1.php -f [NC] but I pretty lost as to how this is implemented.

Any help would be greatly appreciated, Thanks, Rob

robiq

11:47 am on Dec 17, 2007 (gmt 0)

10+ Year Member



Sorry, the 3rd rule I am using is RewriteRule ^([a-z0-9_-]+)+/?$ page.php/$1 [NC]

jdMorgan

1:31 pm on Dec 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want to check for file exists, you'll need to construct the full filepath. Something like:
 
RewriteCond %{DOCUMENT_ROOT}/$1.php -f

Jim

[edited by: jdMorgan at 9:36 pm (utc) on Dec. 17, 2007]