Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-06-2012, 07:57 PM   PM User | #1
doubledee
Regular Coder

 
doubledee's Avatar
 
Join Date: Mar 2011
Location: Arizona
Posts: 617
Thanks: 19
Thanked 0 Times in 0 Posts
doubledee has a little shameless behaviour in the past
Article URL not working

Not sure where to begin describing my issue...

I am working with Pretty URLs for my website which is full of Sections and Articles within those Sections.

If you chose the "Finance" section, then that "navigation tab" would get shaded and you'd be taken to...

http://local.debbie/finance/


The mod_rewrite to make this happen is...
Code:
#PRETTY:		finance/
#UGLY:			articles/index.php?section=finance

#Rewrite only if the request is not pointing to a real file (e.g. add_comment.php, index.php).
RewriteCond %{REQUEST_FILENAME} !-f

#Match any kind of Section.  PHP will decide if it's valid or not.
RewriteRule (.+)/$ articles/index.php?section=$1 [L]
Okay so far...



If you click on one of the Article Summaries on the Finance home page - at the URL above - then you would be taken to a URL like this...

http://local.debbie/finance/articles/postage-meters-can-save-you-money


Now, before I added the concept of "Sections" to my website, an Article would have been located at a URL like this...

http://local.debbie/articles/postage-meters-can-save-you-money


And I was using this mod_rewrite...
Code:
#PRETTY:		articles/postage-meters-can-save-you-money
#UGLY:			articles/article.php?slug=postage-meters-can-save-you-money

#Rewrite only if the request is not pointing to a real file (e.g. add_comment.php, index.php).
RewriteCond %{REQUEST_FILENAME} !-f

#Match any kind of slug.  PHP will decide if it's valid or not.
RewriteRule articles/(.+)$ articles/article.php?slug=$1 [L]
(**I am thinking this mod_rewrite is the culprit to the problem I am about to describe...)




So, here is my current problem...


If you went to the Article above using my new style of URL...

http://local.debbie/finance/articles/postage-meters-can-save-you-money


...then I still want the "Finance" navigation tab highlighted, so that you know what Section you are in.

When my website didn't have any Sections, the PHP I was using to accomplish this was...

PHP Code:
<?php
    $queryString 
$_SERVER['QUERY_STRING'];
?>


<ul id="topMenu">
    <li <?php if($scriptName=="/index.php") echo 'class="current"'?>>
        <a href="/">Home</a>
    </li>

    <li <?php if($queryString=="section=finance") echo 'class="current"'?>>
        <a href="/finance/">Finance</a>
    </li>

    <li <?php if($queryString=="section=legal") echo 'class="current"'?>>
        <a href="/legal/">Legal</a>
    </li>

    and so on...

Unfortunately, now both my PHP and mod_rewrite seem outdated with the addition of "Sections".


To trouble-shoot, I echoed the variable $queryString, and am getting this when I go to that Article...

Code:
slug=postage-meters-can-save-you-money

So clearly my PHP isn't seeing that the Article is in the "Finance" section.


Could someone help me figure out how to adjust my mod_rewrites and PHP so my Navigation Tabs behave properly like before I added the concept of a "Section" to my website??


I tried this code, but got a 500 Error from Apache...
PHP Code:
#PRETTY:        articles/postage-meters-can-save-you-money
#UGLY:            articles/article.php?slug=postage-meters-can-save-you-money

#Rewrite only if the request is not pointing to a real file (e.g. add_comment.php, index.php).
RewriteCond %{REQUEST_FILENAME} !-f

#Match any kind of slug.  PHP will decide if it's valid or not.
##RewriteRule articles/(.+)$ articles/article.php?slug=$1 [L]
RewriteRule (.+)/articles/(.+)$ $1/articles/article.php?slug=$[L

Here is hoping that my changes to handle Sections didn't break this feature of my website?!

Thanks,


Debbie
doubledee is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:19 AM.


Advertisement
Log in to turn off these ads.