MyBB Community Forums

Full Version: Mod_Rewrite help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm doing some voluntary work at my school and we want to modify how the school's website behaves a little. The site was made in a program called RapidWeaver, that seems to have an odd naming convention for files.

We have, for example:
http://site.com/6thform/6thform.html

And we want that to simply be:
http://site.com/6thform

Each directory only has a single HTML file, and none have an index file. So if you browse to http://site.com/6thform right now, you get a directory index.
Now, we will be removing directory browsing via HTACCESS, but that will leave some users with error messages and such.

Is there an easy way to do this without changing every URL, or adding a different DirectoryIndex for each folder?
Hello,

I would recommend getting rid of all those directories and throwing them in your site's root directory if that's where that portion of the site resides. From there, you can just do a simple rewriterule to get something like 6thform to be an alias for 6thform.html (which will solve your directory access issue as well since they'll be taken to the file instead).

Here's a code example for mod_rewrite:

<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine on

RewriteRule ^6thform$ 6thform.html [NC]
</IfModule>

As for the [NC], I'm sure there's a good article out on the web that will help you find the best flags for your rule. The Apache Documentation should have something on it as well.

All the best,
Imad Jomaa.
I already suggested that but the techy in charge of the website is "fussy" to say the least >_> is there any way to do it?

Is there any way to get the directory name via mod rewrite?
I know exactly which site you're on about I believe. Using a regular expression may work - something along the lines of

<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine on

RewriteRule ^(.*)$ /$1/$1.html [NC]
</IfModule>

I'm not an Apache user though, so that may or may not work.
That's the kind of thing im looking for Smile But it doesnt seem to work Confused

But that could completely be my server config, because it keeps giving me permissions errors XD
(2011-11-12, 09:38 PM)Tom K. Wrote: [ -> ]That's the kind of thing im looking for Smile But it doesnt seem to work Confused

But that could completely be my server config, because it keeps giving me permissions errors XD

Could be, or it could be because of my shoddy rewriting Wink Have you checked the apache error logs? They should show you what the rewrite results in, then you can tell if it's correct or not.
I'm fairly sure this is the problem Smile

[Sun Nov 13 00:36:42 2011] [error] [client #MY IP ;)#] client denied by server configuration: /home/school/domains/school.dev-network.com/public_html/.html, referer: http://school.dev-network.com/test/
Hm. Seems the rewrite isn't working properly then if it's trying to load ".html"... Likely due to my poor rewrite skills. Maybe somebody else will have a better understanding.
bump, anyone else have any ideas?