Link to home
Create AccountLog in
Avatar of musqo
musqo

asked on

.htaccess redirect filename to query string

Hello everyone,

I am new to .htaccess and need a quick and dirty solution to redirect a filename to a query string as follows:

/oldfolder/filename.htm  --> /newfolder?variable=filename (*without .htm extension)

Is this possible? And if so, how do I do this? The following is kind of my starting point, but I want to make sure it is correct before adding to my .htaccess file:

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^root/oldfolder(.*).htm /newfolder?variable=$1. [R=301,L]
ASKER CERTIFIED SOLUTION
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of musqo
musqo

ASKER

thank you so much routinet...it worked perfectly!
Strange - should not work if used in .htaccess ...
Why not?  The docs for mod_rewrite show that RewriteLock, RewriteLog, RewriteLogLevel, and RewriteMap cannot be used in an htaccess file, but the rest of the directives should be available at that level.

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
I had not known that.  Thank you for raising the point.  

In that light, it is a bit peculiar that it works.  Perhaps the htaccess file is in the document root directory, instead of a subdirectory.  In that context, the docs imply that the filename will still have the path attached.  I don't believe it would necessarily strip the leading slash for a subdirectory, but I'll have to play with it to make sure.

@musqo: is your htaccess file in the document root for that domain, or is it in the subdirectory you are targeting?