htaccess Question

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I need to change folder/filename to folder_filename.  This seems easy, but
htaccess looks like Greek (or Chinese, or Armenian, or whatever languages
you can't understand) to me.

Thanks in advance.

Adrienne Boswell at Home
Arbpen Web Site Design Services
Please respond to the group so others can share

Re: htaccess Question

Adrienne Boswell wrote:

Quoted text here. Click to load it

Well, it _is_ tricky in the details (i.e. where the &Devil; lives).

Part of the problem is that server software varies, and so do the settings,
and a typical web server admin doesn't even bother telling the poor web
authors what the settings are. So it's quite possible that even if you do
things by the book, they won't work because the server admin disabled a few
features. As far as I know, distributions of Apache and similar software
have disabled more and more features by default. At the extreme, a web
author cannot used .htaccess at all, except perhaps by paying some extra
money to the ISP.

You might think, after reading a nice tutorialish document like
that you could achieve your goal simply by adding

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)_(.*)$ $1/$2

to your .htaccess file. (I'm assuming that "to change folder/filename to
folder_filename" means "to make folder_filename work as an alias for
folder/filename". If you really meant the opposite, you would just make the
obvious modification.)

However, the odds are that you get just some nasty 5xx error page, because
the server settings won't let you use the rewrite engine.

The next attempt is to use something like

RedirectMatch permanent /~jkorpela/test/(.*)_(.*) /$1/$2

As you may guess, I tested this in my test directory only, as some of my
URLs may contain "_", which might cause unpleasant surprises. I hope you can
see how to modify the command. Note that the third argument must be a
relative URL and the fourth argument must be an absolute URL! The rest is
rather easy if you know the basics of regular expressions: .* matches any
string, parentheses are essential (as only parenthesized expressions count
in the replacement expression), and $1 and $2 indicate the strings that have
matched the 1st and 2nd parenthetic expression.

Beware that this is less efficient than the rewrite engine. This approach
means that when a client requests for
then the server processes it and tells the client that the resource has been
permanently moved to
and then the client requests for that. So there's a rather foolish HTTP
transaction here. But this approach typically works if anything useful works
in .htaccess according to your server admin settings.


Re: htaccess Question

Gazing into my crystal ball I observed "Jukka K. Korpela"

Quoted text here. Click to load it

You are my hero, Jukka! Now, when you explain it, it makes more sense.
Yes, I do want to do a permanent redirect.

I'm going to have to play around with it until I get it working correctly
(went somewhere strange once, got a 500 once).  I'll keep at it.

Right now I'm using a custom 404, and it seems to be working okay.  But,
I'll keep at until I get it working.

Thanks again!

Adrienne Boswell at Home
Arbpen Web Site Design Services
Please respond to the group so others can share

Site Timeline