Forum Moderators: phranque

Message Too Old, No Replies

.htaccess rewrite problem for multiple directories

         

volksmenner

12:49 pm on Jul 8, 2008 (gmt 0)

10+ Year Member



i installed drupal, punbb and wordpress in the root and i would like to rewrite the url so as to bypass/hide each of the said directories in favor of root and two subdirectories.

so, site.com/drupal, site.com/punbb/forum, site.com/wordpress/blog should be site.com, site.com/forum and site.com/blog respectively.

the following rewrite works if i use it against one of the directories, for instance punbb.

RewriteEngine on
Rewrite rule ^$ punbb/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ punbb/$1 [L]

but if i use it more than once, punbb and wordpress,

RewriteEngine on
Rewrite rule ^$ punbb/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ punbb/$1 [L]

rewrite rule ^$ wordpress/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ wordpress/$1 [L]

the first entry will work but the second or any thereafter will fail. .htaccess is a complete mystery to me. i have googled until the sun came up literally and nothing explains what the symbols mean (ie. ^$ [L] ect.) so that i might decipher what is going on and how to fix my problem.

any help would be greatly appreciated. :)

g1smd

12:53 pm on Jul 8, 2008 (gmt 0)

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



RewriteRule is not two words.

Each RewriteRule can be preceded by one or more RewriteCond lines.

I would put a blank line after each RewriteRULE to show the logical grouping of your instructions.

Fix that, and post the code again, as then it will make it easier to explain the other problems.

.

^begins with

ends with$

[L] last rule

volksmenner

1:07 pm on Jul 8, 2008 (gmt 0)

10+ Year Member



thanks for the symbol explanations. here is my entire .htaccess code along with the corrections as i understood them. what would you suggest from here because i still get a 500 internal server error.

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ [%1...] [R=301,NC,L]

RewriteRule ^$ drupal/ [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ drupal/$1 [L]

RewriteRule ^$ punbb/ [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ punbb/$1 [L]

RewriteRule ^$ wordpress/ [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ wordpress/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.html [L]

ps. does anyone have a link to where i can learn .htacess code especially the symbols?

g1smd

1:20 pm on Jul 8, 2008 (gmt 0)

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



Thanks for the code tidy up. Now it is much more clear to see each of your rules.

.

Think carefully about these three lines:

RewriteRule ^$ drupal/ [L]

RewriteRule ^$ punbb/ [L]

RewriteRule ^$ wordpress/ [L]

Which one operates for a domain root request (like domain.com/ for example)?

When do the other two operate?

.

Now apply the same logic to the three multi-line rules (the ones with -d and -f in them).

Which three-line block of code will operate for a request with a path?

When do the other two blocks get to do their thing?

volksmenner

2:03 pm on Jul 8, 2008 (gmt 0)

10+ Year Member



ok drupal is the only one which shall operate for root access, therefore i am assuming i do not need:

RewriteRule ^$ punbb/ [L]

RewriteRule ^$ wordpress/ [L]

that was the easy part ... the second half i am not sure at all. from your post i imagine that what i would need to change is the paths of the three line codes.

i think i am missing / before something

RewriteRule ^punbb/(.*)$ /forum/$1 [L]

maybe?

[edited by: volksmenner at 2:03 pm (utc) on July 8, 2008]

g1smd

2:03 pm on Jul 8, 2008 (gmt 0)

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



- Which one operates for a domain root request (like domain.com/ for example)? - The first one.

- When do the other two operate? - Never.

.

I always #comment every line of .htaccess as to what it should do.

It helps me, months later, work out what I was thinking when I wrote it, and often gives me a clue that the code I wrote doesn't quite match the description of what I actually wanted it to do.

In this case, the comment for the first one would have been:

# Rewrite all bare root requests to the /drupal/ folder.

By the time I started to type:

# Rewrite all bare root requests to the /punbb/ folder.

for the second one, I would have thought "Dang! That won't work, the first rule has already kicked in and rewritten to request to the /drupal/ folder!"

.

It is the same logic problem for the "long" rules. Only the first one can ever operate.

For these rules to work independently, each of the different types of URL will need at least the first chanracter to be recognisable (or to have a different extension, like .html and .htm and .php), in order to be able to categorise which resource the request is actually for.

That's down to you to decide which URLs are for which resource.

It's easy to code in to.

It's either a "prefix" on the requested URL, or an extra RewriteCond line on each of the three rules.

volksmenner

12:01 am on Jul 9, 2008 (gmt 0)

10+ Year Member



i really appreciate all your help. but i am at a loss.

the objective - example 1. favor root directory hide subdirectory

default: root -> drupal -> files
http://example.com/drupal/index.php

rewrite: root -> files
http://example.com/index.php

code for example 1.(works like a charm)

RewriteRule ^$ drupal/ [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ drupal/$1 [L]

the objective - example 2. favor subdirectories hide parent directories. (opposite of ex. 1.)

default: root -> punbb -> forum -> files
http://example.com/punbb/index.php

rewrite: root -> forum -> files
http://example.com/index.php

default: root -> wordpress -> blog -> files
http://example.com/wordpress/index.php

rewrite: root -> blog -> files
http://example.com/index.php

i do not know how to implement your suggestions because first i am a noob when it comes to .htaccess and second, ex. 2 is not quite the same as ex. 1 seeing as i want to hide parent directory instead of the child.

i have been at this for an embarrassingly long time. please help me understand better what to do.

my eternal thanks.

philip

jdMorgan

3:24 pm on Jul 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



g1smd is saying that you cannot rewrite the same URL to three different filepaths. Mod_rewrite needs *some* kind of information in the URL itself, in order to decide what to do.

The problem is not solvable with your current URL scheme.

I would suggest a careful and very-critical re-reading of what has already been written in this thread.

Jim