?
Solved

conditions on RewriteRule

Posted on 2012-04-03
12
Medium Priority
?
266 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 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

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

752 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