how can i make a subdirectory look like it doesn't exist?

Discuss practical ways rearrange URLs using mod_rewrite.

how can i make a subdirectory look like it doesn't exist?

Postby i-CONICA » Tue Aug 26, 2008 9:34 pm

Hi, :o

I've been trying to understand mod_rewrite for months now. I'm not an inexperienced web master but I'm still struggling to get to grips with it.

All I want to do is...

I have a domain.com and my forum is installed at domain.com/cgi-bin/forum/-forum here-

When ever a thread is clicked, the forum's url changes to domain.com/cgi-bin/forum/-forum here-/-messagenumberhere-

All i want to do is make it look like this domain.com/-forum here-
and when ever messages are clicked, the url to be domain.com/-forum here-/-messagenumberhere-

Also, Do i just need one "master" .htaccess file at the root of the domain or where do i put it?


I hope i've explained well...

Thank you, I am greatful for any advice..
i-CONICA
 
Posts: 13
Joined: Tue Aug 26, 2008 9:24 pm

Postby richardk » Fri Aug 29, 2008 7:25 am

How many "-forum here-"s are there?

Try the following in a .htaccess file in your document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^[^/]+(?:/[0-9]+)?/?$ /cgi-bin/forum/$0 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby i-CONICA » Fri Aug 29, 2008 11:52 am

Sorry, I read that again. I didn't explain very well.. :(

I've already got mod_rewrite in effect on the forum. But I don't know how to change the rewrite to remove /forum/ from it. because it's a part of the forum scripts also...

I'll show you what i mean...

http://techfeck.com when that's loaded. it shows just that in the address bar..

When a message is clicked. It changes to
http://techfeck.com/forum/m-1219989258/
note the /forum/ that's what i'm trying to remove...

When you click "home" again to return from the thread, to the forums index. It changes to http://techfeck.com/forum/
not http://techfeck.com/ as i'd like...

Have a click around the forum, I think that cleared it up. As i think i'm right in saying you can rewrite a rewrite rule? So one mod_rewrite in a cirtain directory can rewrite the urls of that directory and then a mod_rewrite in the directory above it will rewrite those rules... globally..

I hope I've explained better this time...

I did try removing the /forum/ from the htaccess file for the rewrite already in place but it didn't work.. Because the rewrite in place now changes the script name to /forum/ and it's also in the Perl files for the forum software.. :(

There is only one -forum- that was just me being silly... have a click around, You'll see what i mean... i want the end result to be

http://techfeck.com/
http://techfeck.com/m-1219989258/ when a thread is clicked. then back to the above, when the home button is clicked to return to the index...


I really appreciate your help Richard. I hope I've explained well..
i-CONICA
 
Posts: 13
Joined: Tue Aug 26, 2008 9:24 pm

Postby richardk » Fri Aug 29, 2008 2:31 pm

Post the mod_rewrite you already have.
What is in the PERL files? Mod_rewrite does not change the links that are outputted by scripts (or plain HTML files).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby i-CONICA » Fri Aug 29, 2008 10:18 pm

Code: Select all
Options All Indexes
IndexOptions FancyIndexing
RewriteEngine On
RewriteBase /forum/
RewriteRule ^(.*) /cgi-bin/forum/Blah.pl?$1


Is the mod_rewrite i already have used on the forum...

So I presumed removing the /forum/ would do the trick, But It doesn't...

This is in the Perl file...

Code: Select all
# Filename information
$scriptname = $scriptname || '/forum/'; # Change name of Blah.pl
$modrewrite = $modrewrite || '';       # Setting, mod_rewrite: on = '' | off = '?'


So I presumed changing the /forum/ here would help also.. But nope..

the top line changes the Blah.pl script into /forum/ i think...
i-CONICA
 
Posts: 13
Joined: Tue Aug 26, 2008 9:24 pm

Postby richardk » Sat Aug 30, 2008 11:18 am

So I presumed removing the /forum/ would do the trick, But It doesn't...

Where is the .htaccess file? A .htaccess file in the /forum directory can only control /forum/* URLs.

Delete the .htaccess file in /forum (if there is one).

Try the following in a .htaccess file in your document root
Code: Select all
Options All Indexes
IndexOptions FancyIndexing

RewriteEngine On

RewriteRule ^([bcmv]-.+)?$ /cgi-bin/forum/Blah.pl?$1 [QSA,L]


And try changing
Code: Select all
$scriptname = $scriptname || '/forum/';

to
Code: Select all
$scriptname = $scriptname || '/';
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby i-CONICA » Thu Sep 25, 2008 10:27 pm

Thank you!
That worked perfectly, I've now got the perfect Urls for my forum. Thanks so much!

See what i was aiming for? As simple urls as possible with no /forum/ considering my forum is the only part of that site there is no need for that directory. The above trick worked fine!
http://techfeck.com
i-CONICA
 
Posts: 13
Joined: Tue Aug 26, 2008 9:24 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 24 guests

cron