Forum Moderators: phranque
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]
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
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]
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.