Forum Moderators: phranque

Message Too Old, No Replies

Mod_Rewrite with multiple php files.

Trying to get Mod-rewrite to work with many individual base php files.

         

googalot

2:26 pm on Jun 18, 2004 (gmt 0)

10+ Year Member



First for a bit of background. I run sites that parse .htm as PHP and have many (3000+) base pages that generate dynamic pages in a catalog (300,000+)

The required format is URL/page-name.htm?items=(number)

I have changed this to a friendlier URL/page-name/24/ for example and this works very successfully in the root directory. However for the life of me I cant get the code to work within a subdirectory like

URL/Subdir/page-name/24/ to URL/Subdir/page-name.htm?items=24

Any help in helping me to solve this would be greatly appreciated.

This is the current content of my .htaccess file:

AddType application/x-httpd-php .htm .html

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/]+)/$
RewriteRule ^([^/]+)/([^/]+)/$ /$1.htm?items=$2 [L]

jdMorgan

3:25 pm on Jun 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



googalot,

Welcome to WebmasterWorld [webmasterworld.com]!

You'll have to adjust your pattern in the RewriteRule to allow it to match when additional subdirectory names are prepended to the URL. As it stands now, only root level will be matched if followed by two parameters such as /page-name/24/.

The easiest way may be to simply remove the start anchor from your RewriteRule pattern.

Also, I don't understand your use of RewriteCond. It seems redundant. Can you explain that part, please?

Refs:
Apache mod_rewrite documentation [httpd.apache.org]
Apache URL Rewriting Guide [httpd.apache.org]
Regular Expressions Tutorial [etext.lib.virginia.edu]

Jim

googalot

3:44 pm on Jun 18, 2004 (gmt 0)

10+ Year Member



HI JdMorgan,

Thanks for the welcome and the advice¦:) The reason the condition is there basically is that I don't know what I am doing.

I assumed I needed it to create variables within the Parenthesis in order to use them in the Rule.

I take it from what you say that the variables are indeed being pulled from the Parenthesis in the rule itself.

I tried removing the start anchor but alas to no avail.

Anything else you can suggest would be greatly appreciated as I am at my wits end.

<snip>

All the best,

googalot

[edited by: jdMorgan at 4:35 pm (utc) on June 18, 2004]
[edit reason] Edited per TOS [/edit]

googalot

11:19 pm on Jun 18, 2004 (gmt 0)

10+ Year Member



Thanks Jim for straigtening me out:)

I think I need to rephrase my question. I am more than willing to solve this myself.

I have managed to solve this issue by placing a separate .htaccess file in the subdir and rewriting it like this:

RewriteBase /Subdir/
RewriteRule ^([^/]+)/([^/]+)/$ /Subdir/$1.htm?items=$2 [L]

While I am sure there is a better way to do it, this works for me and I will use it for now until such time as I have figured out how to manage it from a single file.