Go Back   SitePoint Forums > Forum Index > Program Your Site > PHP
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Nov 23, 2009, 06:01   #1
Dan_
SitePoint Enthusiast
 
Join Date: May 2009
Location: Melbourne, Australia
Posts: 35
.htaccess rewrite rule issue

Hi All,

I'm doing a few changes to an online store and have come across the following issue.

Currently links on the webpage (for products) are driven by the below code in the .htaccess file which pulls the corresponding information form an SQL database.

PHP Code:

RewriteBase /


RewriteRule ^New-Product-A.php$ /index.php?cPath=1 [L]
RewriteRule ^New-Product-B.php$ /index.php?cPath=2 [L]
RewriteRule ^New-Product-C.php$ /index.php?cPath=3 [L]
this is for 9 existing products.

If I try to add in a tenth product with the following code it does not work

PHP Code:

RewriteRule ^New-Product-K.php$ /index.php?cPath=10 [L] 

Yet if I change the reference in the first variable (from 1 to 10) it will work.

It would appear that there are only allowed to be 9 active links?

As I’m a little green on this are any assistance would be appreciated.
Dan_ is offline   Reply With Quote
Old Nov 23, 2009, 10:44   #2
PHPycho
SitePoint Wizard
 
PHPycho's Avatar
 
Join Date: Dec 2005
Posts: 1,128
better escape . in rule matching
For example:
RewriteRule ^New-Product-K\.php$ /index.php?cPath=1 [L]
PHPycho is offline   Reply With Quote
Old Nov 23, 2009, 16:12   #3
Dan_
SitePoint Enthusiast
 
Join Date: May 2009
Location: Melbourne, Australia
Posts: 35
Hi PHPycho (great name)

It appears that I've missed the \ after the product in my excerpt of code.

Unfortunately I am unable to edit it above and still have the issue.
Dan_ is offline   Reply With Quote
Old Nov 23, 2009, 21:05   #4
PHPycho
SitePoint Wizard
 
PHPycho's Avatar
 
Join Date: Dec 2005
Posts: 1,128
Quote:
Originally Posted by Dan_ View Post
Hi PHPycho (great name)

It appears that I've missed the \ after the product in my excerpt of code.

Unfortunately I am unable to edit it above and still have the issue.
As far as i know following meta characters needs to be escaped:

^
$
(
)
<
.
*
+
?
[
{
\
|
>
PHPycho is offline   Reply With Quote
Old Nov 23, 2009, 22:17   #5
Dan_
SitePoint Enthusiast
 
Join Date: May 2009
Location: Melbourne, Australia
Posts: 35
hmm I’m out of my depth here (time to hit the books)

I have made the line identical to all others (as per your example) and the new rules will not work, yet simply changing the path on any of the old rules to the new path works.
Dan_ is offline   Reply With Quote
Old Nov 23, 2009, 23:07   #6
PHPycho
SitePoint Wizard
 
PHPycho's Avatar
 
Join Date: Dec 2005
Posts: 1,128
Can you post the error logs?
So that we can help if we got the clue.
Thanks
PHPycho is offline   Reply With Quote
Old Nov 24, 2009, 18:58   #7
Dan_
SitePoint Enthusiast
 
Join Date: May 2009
Location: Melbourne, Australia
Posts: 35
I sure can,

Where are the error's logged?
Dan_ is offline   Reply With Quote
Old Nov 24, 2009, 19:40   #8
PHPycho
SitePoint Wizard
 
PHPycho's Avatar
 
Join Date: Dec 2005
Posts: 1,128
Quote:
Originally Posted by Dan_ View Post
I sure can,

Where are the error's logged?
If you have ftp access & have previlage you can check for error_log or something else.
PHPycho is offline   Reply With Quote
Old Nov 24, 2009, 19:44   #9
Dan_
SitePoint Enthusiast
 
Join Date: May 2009
Location: Melbourne, Australia
Posts: 35
Quote:
Originally Posted by PHPycho View Post
If you have ftp access & have previlage you can check for error_log or something else.
This is hosted on a XAMPP in a virtual server.

There is an error log in the htdoc directory but is contains no recent entries
Dan_ is offline   Reply With Quote
Old Nov 25, 2009, 01:09   #10
Dan_
SitePoint Enthusiast
 
Join Date: May 2009
Location: Melbourne, Australia
Posts: 35
Ok I think I have figured it out (simply really *sigh*)

When I open the updated file in notepad (not notepad++) there are a couple of hidden characters in front of the changes I made. If I remove those characters it works (but I loose all the formatting for readability)

By opening the original file and my updated file side by side in Notepad++ it appears that they are in different formats.

The original can be converted to either Windows or Unix format, so I assume it's in a Mac format.

The update can be converted to either Unix or Mac (hence it is in a Windows format I assume)

Now on xmapp the windows format works fine but a quick test on the live site resulted in a 500 error.

I believe that it may need to be changed to a Mac format and upload so the site is happy.

I'll test this later but does my understanding seem logical as to why it would not work?
Dan_ is offline   Reply With Quote
Old Nov 25, 2009, 02:20   #11
Dan_
SitePoint Enthusiast
 
Join Date: May 2009
Location: Melbourne, Australia
Posts: 35
Ok more of an update, By retyping it all for some reason the file now works.

However a new issue has arisen.

Loading either the unix or windows version of the file (which run fine on XAMPP) crash the live server.

Loading the mac version allows the homepage to come up, then breaks all the links.

I fail to understand why this is and here is a copy of the error message.

Internal Server Error
The server encountered an internal error or a misconfiguration and was unable to complete your request
Please contact the server administrator and inform them of the error that occurred.
More information about this error will be in the server error log
Additionally a 500 Internal Server Error was encountered while trying to use an Error Document to handle the request.

I'll keep digging
Dan_ is offline   Reply With Quote
Old Nov 25, 2009, 03:38   #12
Dan_
SitePoint Enthusiast
 
Join Date: May 2009
Location: Melbourne, Australia
Posts: 35
Dig no more...(sorta)

PHPycho, you are not going to believe this.

I have solved the issue and have the new links working, But I’m yet to understand why (and I will investigate so to learn why)

I noticed then when I FTP the file to the server it was not asking me to confirm an overwrite (which is odd as the file was to be overwritten)

Out of frustration (and lack of ideas) I manually rewrote the whole file again in notepad. The difference this time was that I wrote it in my main window (not the virtual machine)

Now I go to FTP the file and it asks me to confirm the overwrite. I say yes and presto all works as it should.

Now I have no idea why or how but it does. It would appear that there is a difference between my machine and the virtual machine as writing both in notepad (the same version mind you) produced different results?

I just need to track down the variable that is different so I can learn to not make the same mistake again. Plus I would like to code in my vm at times.

Many thanks for your assistance.
Dan_ is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
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
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 22:43.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved