Forum Moderators: phranque

Message Too Old, No Replies

my first real work with Mod Rewrite and rules

I think the processing is happening twice - need to read folders

         

sfullman

2:08 am on Mar 26, 2011 (gmt 0)

10+ Year Member



Hi there,

Hope to be concise here. First real intensive use of RewriteRule's in the .htaccess file. Here is my attempted coding:

# ----------- real pages we wish to preserve --------------
RewriteRule ^cms3.01.php$ cms3.01.php #a specific page I want to keep from rewrites
RewriteRule (.*).js$$1.js #should be common sense..
RewriteRule (.*).css$$1.css #should be common sense..

#------------ pages with folders=components ---------------
RewriteRule ([^/]+)/(.+)(.php)$ index.php?component=$1&node=$2"
RewriteRule ([^/]+)/(.+)$ index.php?component=$1&node=$2

#------------ all other strings - this is restrictive -------------
RewriteRule (.+)(.php)$ index.php?node=$1
RewriteRule (.+)$ index.php?node=$1


The logic above is:
1. preserve .js and .css pages
2. .php extension is discarded - /page is the same as /page.php
3. URL's with format of folder/file.php - folder is treated as the component or module for the site application
4. URL's without a folder like /file.php - same page but component variable not passed.

However it is not working. Can anyone assist me with this?

I am active in the community over at php builder, sorry I can't be of more help here but really appreciate the review and solution to this

g1smd

2:59 am on Mar 26, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Don't add comments to a line of code. It will crash the server. Put comments on the line before.

Leading .* and .+ patterns kill your server efficiency. Use [^/]+/ or [^.]+\. or similar.

Escape literal periods in patterns.

Every rule needs the [L] flag.

I haven't looked at the functionality yet.

Be aware that RewriteRule is defined in terms of URL requests. Those URLs are defined in the links on your pages.

sfullman

10:22 am on Mar 26, 2011 (gmt 0)

10+ Year Member



I have probably spent 5 hours on this with no headway whatsoever, getting internal server errors, trying to add a rewritelog and failing on that, all I'm trying to do is:

*.css or *.js is not rewritten
specific_file_1.php is not rewritten
any_folder/any_file(\.php)* is rewritten to file1.php?component=any_folder&node=any_file
any_file(\.php)* is rewritten to file2.php?node=any_file

Can you help me with that? In so doing maybe I'll see what I'm not understanding about this...