Solved

conditions on RewriteRule

Posted on 2012-04-03
12
263 Views
Last Modified: 2012-04-03
Hello,

I have a mod rewrite which works great, it is grabbing all page addresses in a certain folder and rewriting them into PHP usable query string.

RewriteRule car-auto-insurance-news/([a-z0-9-_]+)\.php$ car-auto-insurance-news/news_page.php?page=$1  [nc]

the problem is that is grabs every page in that folder.. i want to add a condition which is..

if page = insurance-news-articles.php, then DONT run the re-write, but do it to every other page


so roughly I need it to look like this in my .htacess file, i just dont know how to write it

if (page == insurance-news-articles.php)  {

 // do nothing

} else {

 RewriteRule car-auto-insurance-news/([a-z0-9-_]+)\.php$ car-auto-insurance-news/news_page.php?page=$1  [nc]

}
0
Comment
Question by:jblayney
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
12 Comments
 
LVL 21

Expert Comment

by:Papertrip
ID: 37801547
Add the following immediately above that RewriteRule

RewriteCond %{REQUEST_URI} !^/insurance-news-articles.php$ [NC]

Open in new window


Based on your existing RewriteRule you may or may not need that carrot and slash before insurance in the RewriteCond, depends on what the base URL is for these rules.  Not sure since there isn't much context given.

The main parts here are request_uri and the !
0
 
LVL 1

Author Comment

by:jblayney
ID: 37801676
Hello Papertip,
that works, it has a weird bug though, I have a  PHP recordset on insurance-news-articles.php and it is not running anymore, if I remove the htacess code the page runs fine..
the rewrite conditions seem to be killing my database connection and display, any ideas?
0
 
LVL 1

Author Comment

by:jblayney
ID: 37801717
Hi Papertip,

on testing further i just realized it isnt working at all, it is still redirecting the page to news_page.php it just rewrote the URL
0
Save the day with this special offer from ATEN!

Save 30% on the CV211 using promo code EXPERTS30 now through April 30th. The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 37801725
Just a thought... It might be easier to keep things organized if your scripts that need rewriting are in a separate directory from those that do not need rewriting.
0
 
LVL 21

Expert Comment

by:Papertrip
ID: 37801742
Try adding another RewriteCond

RewriteCond %{REQUEST_URI} car-auto-insurance-news/([a-z0-9-_]+)\.php$

Open in new window

0
 
LVL 21

Expert Comment

by:Papertrip
ID: 37801751
If Ray has a php-based suggestion for this like he mentioned I would listen to his advice.
0
 
LVL 21

Expert Comment

by:Papertrip
ID: 37801786
Also, for now and future reference, posting more context is always helpful.  All you gave was a single RewriteRule and we have no idea what else is happening in your conf files that could or could not be affecting this.
0
 
LVL 1

Author Comment

by:jblayney
ID: 37801788
Hi Papertip and Ray,

Ray I had that thought from the beginning, client was very specific about URL for SEO, I think i may get them to do your suggestion as it gives 1 more level of keyword/ folder writing

Papertip, no luck, i tried with both, each separately, with slash, without, right now it looks like so.


RewriteCond %{REQUEST_URI} !^/insurance-news-articles.php$ [NC]
RewriteCond %{REQUEST_URI} car-auto-insurance-news/([a-z0-9-_]+)\.php$
RewriteRule car-auto-insurance-news/([a-z0-9-_]+)\.php$ car-auto-insurance-news/news_page.php?page=$1  [nc]
0
 
LVL 1

Author Comment

by:jblayney
ID: 37801802
Papertip, the whole file


RewriteEngine On
Options +FollowSymLinks

#non www to www
RewriteCond %{HTTP_HOST} ^website\.ca
RewriteRule (.*) http://www.website.ca/$1 [R=301,L]

RewriteCond %{REQUEST_URI} !^/insurance-news-articles.php$ [NC]
RewriteCond %{REQUEST_URI} car-auto-insurance-news/([a-z0-9-_]+)\.php$
RewriteRule car-auto-insurance-news/([a-z0-9-_]+)\.php$ car-auto-insurance-news/news_page.php?page=$1  [nc]


# Added for Custom Errors
ErrorDocument 401 http://www.website.ca/400.php
ErrorDocument 401 http://www.website.ca/401.php
ErrorDocument 403 http://www.website.ca/403.php
ErrorDocument 404 http://www.website.ca/404.php
ErrorDocument 500 http://www.website.ca/500.php

redirect 301 /index.html http://www.website.ca/index.php
redirect 301 /web/index.php http://www.website.ca/index.php
redirect 301 /web/services.php http://www.website.ca/index.php
redirect 301 /web/auto-insurance.php http://www.website.ca/index.php
redirect 301 /web/privacy.php http://www.website.ca/index.php
redirect 301 /web/auto-insurance.php http://www.website.ca/index.php
redirect 301 /web/auto-insurance.php http://www.website.ca/car-auto-insurance/car-insurance-ontario/insurance-quotes-ontario.php
0
 
LVL 21

Expert Comment

by:Papertrip
ID: 37801812
I'll step back and let Ray take a stab from his side since it sounds like a better idea.  Sorry for not testing those rewritecond's first, I will have some time soon to test unless you get it resolved in the meantime.
0
 
LVL 1

Author Comment

by:jblayney
ID: 37801901
Hi Papertip, the recordset problem is not the problem, the condition doesn't work...

ray doesn't have a PHP solution, a good solution, but one I have to sell
0
 
LVL 1

Author Closing Comment

by:jblayney
ID: 37801962
client loved the idea, easy sell, i shouldn't have wasted 2 hours messing with htacess
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

739 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