hide directory in the url

Discuss practical ways rearrange URLs using mod_rewrite.

hide directory in the url

Postby volksmenner » Wed Jul 09, 2008 4:07 pm

i have been struggling with this problem for sometime and desperately seek some kind of solution. i wish to hide two directories in the url in favor of their sub-directories.

example 1.

here is what i have:

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

here is what i want to accomplish:

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

again with a different directory:

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

here is what i want to accomplish:

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

so in conclusion i want to get rid of both punbb and wordpress in the url.

---

example 2.

in this example i successfully redirected a subdirectory (drupal) to the root (example.com).

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

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

code for example 2.(works like a charm)

RewriteRule ^$ drupal/ [L]

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

but nothing i have tried with example 1 works. help please.
volksmenner
 
Posts: 4
Joined: Wed Jul 09, 2008 3:41 pm

Postby richardk » Wed Jul 09, 2008 4:57 pm

Is it /punbb/forum/index.php or /punbb/index.php?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^forum(/(.*))?$ /punbb/$2     [QSA,L]
RewriteRule ^blog(/(.*))?$  /wordpress/$2 [QSA,L]

RewriteRule ^$ /drupal/ [QSA,L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule !^(forum|blog|punbb|wordpress)(/.*)?$ /drupal%{REQUEST_URI} [QSA,L]

You may need to replace /punbb/$2 with /punbb/forum/$2 and /wordpress/$2 with /wordpress/blog/$2.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby volksmenner » Wed Jul 09, 2008 5:18 pm

thanks! you are a genius and a genuine humanitarian!

i have searched near and far for this solution ... incredible.

as it turns out, i did have to replace /punbb/$2 with /punbb/forum/$2 and /wordpress/$2 with /wordpress/blog/$2. (in no way is that a complaint it is just for documentations sake.)

so now i am going to study your code to see exactly how you did it.

thanks a million! may good fortune find you always. :)

---

EDIT. i just discovered a slight problem. the landing pages for each of these is a huge success. however, when you click a link, punbb returns to the url.

so http://example.com/forum turns into http://example/punbb/forum/link.php when you click a link. any way around this so that i can get http://example.com/forum/link.php

---

EDIT. nevermind. i realized that i had to change the base url in config.php file. oops. :)
volksmenner
 
Posts: 4
Joined: Wed Jul 09, 2008 3:41 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 73 guests

cron