Forum Moderators: phranque
My friend has a website that will allow give users a public view of some data. this data would be located at "https://secure.website.com/login/MyLogs.swf?u=username"
What we would like to do is to make it so that if a user goes to:
"http://website.com/mylogs/username" it gets redirected to the above url.
I got this to work with the following:
RewriteRule ^MyLogs/(.+)$ [secure.website.com...] [L]
This works, but it would be ideal if only the friendly url was shown, not the actual. I understand that this happens with external redirection. So, I thought maybe it would be sufficient to have the friendly URL be: "https://secure.website.com/mylogs/username" This shouldn't be too hard. But I thought it would be good to put some rules in place so I currently have this:
RewriteCond %{HTTP_HOST} secure.website.com [NC]
RewriteRule ^MyLogs/([a-zA-Z0-9_-]+)$ /login/MyLogs.swf?u=$1 [NC,L,R]
this sort of works. problems i have are a) i would like to be able to force https and i don't know how to do this. the only example i could find show it in httpd.conf and i dont have access to that.
b) when I have the [R] at the end, it redirects and shows the new URL. When I take it out, i doesn't redirect properly and I don't know what it's doing. I get an invalid username which I am told means I am not providing a username, so it's not passing it properly.
Any ideas?
Welcome to WebmasterWorld!
I think this should get you close:
HTTPS
Will contain the text "on" if the connection is using SSL/TLS, or "off" otherwise. (This variable can be safely used regardless of whether or not mod_ssl is loaded).[httpd.apache.org...]
RewriteCond %{HTTPS} !^on$ [OR]
RewriteCond %{HTTP_HOST} !^(secure\.website\.com)?$
RewriteRule ^MyLogs/([a-z0-9_-]+)$ https://secure.website.com/mylogs/$1 [NC,R=301,L]RewriteCond %{HTTPS} ^on$
RewriteCond %{HTTP_HOST} ^(secure\.website\.com)?$
RewriteRule ^MyLogs/([a-z0-9_-]+)$ /login/MyLogs.swf?u=$1 [NC,L]The second A-Z is really unnecessary when using NC... all it does it add processing to the regex. I'm not sure why you're not getting the correct username, because your pattern and back-reference look correct, but I'm not too familiar with https, so I'm not sure if that might have something to do with the issue or not.
The second rule is essentially what you had, but removes the incorrect "R" flag and eliminates "A-Z" from the pattern, since it is redundant if you use an [NC] flag.
You may even need to check %{HTTP_HOST} in that second rule -- it depends on exactly how your server maps domains to directories...
# Redirect to https if secure.example.com requested using http
RewriteCond %{HTTP_HOST} secure\.example\.com [NC]
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(.*)$ https://secure.example.com/$1 [R=301,L]
#
# Rewrite 'friendly' URL requests to 'unfriendly' filepath
RewriteCond %{HTTP_HOST} secure\.example\.com [NC]
RewriteRule ^MyLogs/([a-z0-9_\-]+)$ /login/MyLogs.swf?u=$1 [NC,L]