?
Solved

conditions on RewriteRule

Posted on 2012-04-03
12
Medium Priority
?
269 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month16 days, 16 hours left to enroll

864 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