Welcome to WebmasterWorld Guest from 34.229.194.198

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

mod_rewrite in a subfolder

I'm so close I can feel it

     
10:43 am on Jul 16, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 23, 2003
posts:165
votes: 0


here's my situation.
I have a folder on my site called say widget and that can have one or more variables e.g widget/?var1=foo&var2=bar
i want all three situations to work
www.com/widget/
www.com/widget/foo/
www.com/widget/foo/bar/

if trailing slashes are missing the page still needs to work.

currently the rewrite rule is stored in a .htaccess file inside the widget folder I can get the following to work

www.com/widget/
www.com/widget/foo/
www.com/widget/foo/bar/

but www.com/widget (minus the trailing /) gives this
www.com/widget?var1=C:&var2=Inetpub/wwwroot/site/widget

which shows the right webpage but is an ugly URL.

Here's my code


RewriteEngine On
RewriteRule ^([^/]+)/(.+)$?artist=$1&album=$2
RewriteRule ^([^/]+)$ $1/
RewriteRule ^([^/]+)/$?artist=$1

I think the first rule is giving the problem above but, a sit stands playing around with it I can't manage to get all three combos to work. There is no rewrite rule in the parent folder conflicting with it.

any clues?

p.s. I have read the mod_rewrite manual and numerous tutorials but am still stuck. Help.

3:06 pm on July 18, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


It's not clear what you are trying to rewrite here. It would help if you would post a few detailed examples, like

Rewrite from /widget/ or /widget to /widget?query=abc
Rewrite from /widget/foo/ or /widget/foo to /widget/foo?query=abc

I attempted to derive this from your posted rules, but only the second one has correct syntax; The others are missing either the substitution URL or a space between the pattern and substitution URL. So I don't know what you are trying to accomplish.

Jim

8:09 am on July 19, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 23, 2003
posts:165
votes: 0



RewriteEngine On
RewriteRule ^([^/]+)/(.+)$?var1=$1&var2=$2
RewriteRule ^([^/]+)$ $1/
RewriteRule ^([^/]+)/$?var1=$1

I am attempting to get

www.com/widget/foo/bar/ from?var1=foo&var2=bar

sometimes only 'foo' will be present (with or without trailing slash) and sometimes both 'foo' and 'bar' will be present (with or without trailing slash). Then if neither 'foo' nor 'bar' are present obviosuly the widget folder gets shown. At present if neither foo nor bar are present then the url shows
www.com/widget/?var1=C:&var2=Inetpub/wwwroot/site/widget
12:57 am on July 20, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


OK, if I understand what you're trying to do, this should work better:

RewriteEngine On
RewriteRule ^([^/]+)/(.+)$ /widget/?var1=$1&var2=$2 [L]
RewriteRule ^(.+)$ /widget/?var1=$1 [L]

If this shows the same problem, then you've got some code in a higher .htaccess file or in httpd.conf that is incorrect -- It appears to be appending the value of DOCUMENT_ROOT to the URL if the trailing slash is missing. Also, make sure you've got content negotiation disabled (by using Options -MultiViews if necessary).

Jim

5:52 pm on July 21, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 23, 2003
posts:165
votes: 0


They seem to be generating the same problems as I was having.

This code


RewriteEngine On
RewriteRule ^([^/]+)/(.+)$?artist=$1&album=$2 [L]
RewriteRule ^([^/]+)/([^/]+)$?artist=$1&album=$2 [L]
RewriteRule ^([^/]+)$ $1/ [L]
RewriteRule ^([^/]+)/$?artist=$1 [L]

seems to work for everything except www.com/widget which redirects to www.com/widget?var1=C:&var2=Inetpub/wwwroot (on windows) and produces a 500 error (on Linux) - NB. the site sits as a subdomain of another domain and has its own unique domain name.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members