Forum Moderators: phranque
www.mydomain.com/dir1 --> www.mydomain.com/index.php?numvar=1&var1=dir1
www.mydomain.com/dir1/dir2 --> www.mydomain.com/index.php?numvar=2&var1=dir1&var2=dir2
etc.
Here is the .htaccess code
options +FollowSymlinks
RewriteEngine On
#if the URL does not have a trailing backslash
RewriteCond $1!/$
#Append the trailing backslash
RewriteRule (.+) [mydomain.com...] [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ index.php?numvar=5&var1=$1&var2=$2&var3=$3&var4=$4&var5=$5 [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ index.php?numvar=4&var1=$1&var2=$2&var3=$3&var4=$4 [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ index.php?numvar=3&var1=$1&var2=$2&var3=$3 [L]
RewriteRule ^([^/]+)/([^/]+)/$ index.php?numvar=2&var1=$1&var2=$2 [L]
RewriteRule ^([^/]+)/$ index.php?numvar=1&var1=$1 [L]
The code works fine when I only include the rules for 2,3,4 or 5 directory "depth" URL's (by commenting out the last line) but when I uncomment the last line EVERY time I get numvar=1 and var1=index.php regardless of whether the URL is depth = 1, 2, 3, 4, or 5.
I am sure it is something simple but I just can't figure it out...any help appreciated! Thanks!
Therefore, your first and last rules create a neat little loop. Any of your expected URLs are rewritten to /index.php?var1=xyz&var2=... etc, and mod_rewrite restarts. Since there is no trailing slash, the first rule will add one. Now index.php/?var1=xyz&var2=... neatly matches the last rule, so it is rewritten to /index.php?var1=xyz *again*.
I'd suggest you change the first rule like this:
# if the URL does not have a trailing backslash [b]or contain a period[/b]
RewriteCond $1 !(\.¦/$)
# append a trailing backslash
RewriteRule (.+) http://www.example.com/$1/ [R=301,L]
Note that you will have to change the broken pipe "¦" character to a solid pipe character before use; Posting on this forum modifies that character.
Jim
[edited by: jdMorgan at 3:19 am (utc) on April 19, 2006]
Thanks a bunch for your response. Curious about your choice of showing it as a 301 redirect. My intention is to have a series of crawlable page like www.mydomain.com/finance/mortgage/application and www.mydomain.com/entertainment/sports/baseball/orioles which are the pages that I want the Search engines to see. Won't the 301 redirect have the search engines see www.mydomain.com/index.php?numvar=3&var1=finance&var2=mortgage&var3=application
I'll test your code in a few minutes and let you know the result.
Thanks,
Matt
Thanks again for the help!