Solved

conditions on RewriteRule

Posted on 2012-04-03
12
260 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
  • 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
 
LVL 108

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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
File submission to SQL Server 1 37
<? versus <?php 5 36
Load google maps api into wordpress 5 35
Regex PHP lines with newlines not being matched - all other match fine 4 21
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

932 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

14 Experts available now in Live!

Get 1:1 Help Now