Forum Moderators: phranque

Message Too Old, No Replies

yet another rewrite issue

always with the access errors

         

ghostcorps

5:46 am on Sep 8, 2004 (gmt 0)

10+ Year Member



Hi guys,

I have been frantically scouring the net (including this forum) for somthing that will click with me or (we can wish) solve my problem. but alas.. this regular expression stuffs is still only a few days old to me.. so as you may guess, I'm lost... have been writting my htaccess file and implementing it over and over.. but to no avail. All I get is access errors every time.

I have included most of it below but only the two most complex dynamic URLs to be rewritten and also cutting out a massive list of conditions to block spam bots. index.php and .htaccess are located in www.url.com.au/xyz/cart/. If someone could throw a hint or two my way It would be greatly appreciated.

XBitHack full

my understanding is that the line below would remove the '.PHP' from index.PHP..?

AddType application/x-httpd-php .

RewriteEngine ON

RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR] (massive list)

below should hide the .htaccess file

RewriteRule ^\.htaccess$ - [F]

Note the three sets of numbers in the line below, these identify the page as category_sub-category_sub-sub-category.. order of browsing goes like this. ~cpath=## => ~cpath=##_## => ~cpath=##_##_## => ~cpath=##_##_##&products_id=#. I have written an entirly seperate RewriteRule for each level. is this necessary?

#~cart/index.php?main_page=product_info&cPath=5_23_31&products_id=8
RewriteRule ^main/([a-z]+)/catalogue/([0-9]+.[0-9]+.[0-9]+)/products_id/([0-9]+/$ index.php?main_page=$1&cPath=$2&products_id=$3

#~cart/index.php?main_page=advanced_search_result&keyword=barbell&categories_id=&inc_subcat=1&pfrom=5&pto=6
RewriteRule ^main/([a-z]+.[a-z]+.[a-z]+)/searchwords/([a-z0-9]+)/category/([a-z0-9]*)/subcat/([a-z0-9]*)/lowestprice/([0-9]*)/highestprice/([0-9]*)/$ index.php?main_page=$1&keyword=$2&categories_id=$3&inc_subcat=$4&pfrom=$5&pto=$6

I know its abit overly complicated for someone with as little knowledge as I have... but i figure i might as well do it completly the first time.

=^_^=

i should also mention (just in case) that i am trying to change a "directory" (dymanic URL) to a query string (static URL).

jdMorgan

1:55 pm on Sep 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ghostcorps,

Welcome to WebmasterWorld!

> ...access errors.

I assume you mean 404-Not Found, rather than 500-Server Errors. If not, the following may not apply.

> I have written an entirly seperate RewriteRule for each level. is this necessary?

No, but if you don't have separate rules, you will end up with blank parameters, e.g. "subcat=&subsubcat=&products_id=" passed to your script. So the answer depends on the script's ability to handle that.

If you do use multiple rules, put the one with the most parameters first, and end it with an [L] flag.

Nothing jumps out at me here. I'd suggest you test the rules one at a time, and temporarily change the rules to external redirects, so that you can see the result in the browser address bar, e.g.

RewriteRule ^main/([a-z]+)/catalogue/([0-9]+.[0-9]+.[0-9]+)/products_id/([0-9]+/$ http://yourdomain.com.au/xyz/cart/index.php?main_page=$1&cPath=$2&products_id=$3 [R=301,L]

If your site is live, you can create a test subdirectory and put the .htaccess file there so as not to disturb your site while testing.

The only thing I see that looks "wrong" is "[a-z]+.[a-z]+.[a-z]+" -- Remember that "." means "any single character," so this pattern looks rather ambiguous. If you want a literal period match, use "\." instead.

Test one rule at a time, get each working, then start combining them.

Jim

ghostcorps

11:37 pm on Sep 8, 2004 (gmt 0)

10+ Year Member



wow.. thanks, I feel welcome already, I hope I dont hassle you guys too much.. im a fast learner.. but can get stuck on the finer points :)

yes.. i have a carbon copy of my site as a test ground. Unfortunatly my providers server is down for a cople days... something to do with their bulk provider.. looks liek it could be messy.. but thats off topic. I'll write the multiple rules-in. But then hash them out as i test.

Ive been looking at it again.. and I think this one

AddType application/x-httpd-php .
Wont work.. cant test for another day or two... but is there any other way to remove .PHP so it looks liek a directory rather than a file.

(~[0-9]+.[0-9]+.[0-9]+)/

is actually defining ##_##_## so would i be correct to assume you meant \_? not \.

jdMorgan

1:21 am on Sep 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> AddType application/x-httpd-php .
> Wont work... is there any other way to remove .PHP so it looks liek a directory rather than a file.

That's not what the AddType directive does, so I'm not sure of the question.
AddType application/x-httpd-php .php
sets the MIME-type of all files with an extension of .php to application/x-httpd-php

There does not seem to be any consensus on the "correct" way to turn on php processing. It varies by whether php is installed as a module or as cgi. You can try this search [google.com] for more information.

> so would i be correct to assume you meant \_? not \.

Sort of, as I had assumed you wanted to match literal periods, as I posted above. The unescaped period has special meaning to regular expressions, and so needs to be escaped if you want to match a literal period. If you wish to match an underscore, just put an underscore in your pattern; underscores have no special meaning in regular expressions.

Jim

ghostcorps

1:55 am on Sep 9, 2004 (gmt 0)

10+ Year Member



thanks have fixed my pattern as suggested to:
([0-9]+_[0-9]+_[0-9]+)

I have just been looking at [websiteoptimization.com ] it talks about setting 'multiview' through .htaccess to remove file extentions from URLs, Is this a viable option? :edit: further investigations would suggest not.

or could i simply drop

<Files index>
ForceType application/x-httpd-php
</Files>
into it?

ghostcorps

3:14 am on Sep 9, 2004 (gmt 0)

10+ Year Member



#removes .PHP from URL
<Files index>
forcetype application/x-httpd-php
</Files>
#removes the included tags from applicable files
<FilesMatch "\.(gif夸pe?g如ng如df在mp)$">
forcetype none
</FilesMatch>

this is what i have come up with so far. Am thinking though.. couldnt i simply add PHP to the <filesmatch~ Rule?

coopster

5:48 pm on Sep 9, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Can you clarify something? It's not clear, but it seems as though you want to continue parsing files with PHP, just not show a PHP extension? If so, maybe Hiding PHP [php.net] will be of some help.

ghostcorps

12:32 am on Sep 10, 2004 (gmt 0)

10+ Year Member



Thanks for the link. Yes, along with making the dynamic URLs appear static, I am trying to remove all extentions so that all my URLs are cleaner, But as my site is a regularly updated shopping cart product, I would rather not go in and change the PHP scripts. So I am concentrating on my htaccess.

The 'Forcetype' code (which is again suggested in the link) is to specifically remove .PHP from index.PHP.

The 'FilesMatch' code is to remove picture extentions.. again trying to keep the URL as clean as I can.

Would it not be possible to add PHP to the 'filesmatch' code parameters?

ghostcorps

1:52 am on Sep 10, 2004 (gmt 0)

10+ Year Member



My server is finnally back up so i have begun testing my script.

I started with having only this:

<Files index>
forcetype application/x-httpd-php
</Files>

and also tried only this

<FilesMatch "\.(gif夸pe?g如ng屹ip如df在mp如hp)$">
forcetype none
</FilesMatch>

in the htaccess.

but received this both times.

Fatal error: Failed opening required 'includes/languages/english.php' (include_path='.:/php/includes:/usr/share/php') in /home/virtual/site294/fst/var/www/html/bec/zencart/includes/application_top.php on line 349

Any clues as to where have i gone wrong?