Forum Moderators: phranque
I got a lot of help from this forum to use mod_rewrite in .htaccess and redirection with user authentication. But still facing issues realted to relative paths. Here is .htaccess
RewriteEngine on
RewriteCond $1!^user_
RewriteCond %{REMOTE_USER} ^([0-9.0-9.0-9.0-9]+)$
RewriteRule (.*) hello/%1/index.html [L]
AuthType Basic
AuthuserFile /usr/local/.htpasswd
AuthName "PROTECTED"
require valid-user
AuthType Basic
deny from all
I am using IP address as user (e.g. 192.168.199.1). Redirection is working perfectly and it takes me to the required page. But i have few links on the opened page and also some images which donot appear. Whenever i click on any link on the page it keeps me on the same page. I guess due to
RewriteRule (.*) hello/%1/index.html [L]
Can anybody Help?
I guess Jim can help me Out :)
Thanks,
Gaurav
RewriteCond $1 !^hello_
RewriteCond %{REMOTE_USER} ^([0-9.]+)$
RewriteRule (.*) hello/%1/index.html [L]
Consider two things:
1) You are rewriting *all* URLs to hello/<Remote-IP>/index.html, so that means that requests for all images, CSS files, external javascripts --everything-- will be rewritten to your .html index page. That's probably not what you want.
2) If a remote user's IP address changes, he will no longer be able to access his files. You might consider a different method of mapping users to subdirectories. Using per-user subdomains is a popular method.
Jim
RewriteCond $1!^hello_
RewriteCond %{REMOTE_USER} ^([0-9.]+)$
RewriteRule index.html hello/%1/index.html [L]
Links on index.html page are still not working. All the links are relative to index.html.
192.168.199.1
--- index.html
--- #*$!x.html
--- yyyy.html
I have put a link for #*$!x.html & yyyy.html on index.html page. All these pages resides on the same directory i.e. "192.168.199.1". But i can't still open the link. When i click on link, it takes me to abcd.com/#*$!x.html which doesnot exist, rather it should take me to abcd.com/hello/192.168.199.1/#*$!x.html
Please help me in fixing this issue. Shall be very grateful to you. :)
Thanks,
Gaurav Pruthi
If you want to rewrite *All* requests from *every* remote_user to separate subdirectories, then the following code will do that:
RewriteCond $1 !^hello
RewriteCond %{REMOTE_USER} ^([0-9.]+)$
RewriteRule (.*) hello/%1/$1 [L]
It's likely that there will be some URLs that you do not wish to rewrite. Just for an example, let's assume that you do not wish requests for robots.txt to be rewritten to the user subdirectories. In that case, you can add further exclusions:
RewriteCond $1 !^robots\.txt$
RewriteCond $1 !^hello
RewriteCond %{REMOTE_USER} ^([0-9.]+)$
RewriteRule (.*) hello/%1/$1 [L]
One more query. Things are working pretty well but having little problem. I am getting redirected to the user's directory and all links on the page are working perfectly too. Now the issue is that like if i am accessing the following link
[abcd.com...] whose actual path is Document_root/hello/192.168.199.1/192.168.199.1_user.html
Now when i am logged in. If i change the URL from
[abcd.com...]
to
[abcd.com...]
I am able to access the page. Please note I have changed the IP from 1 to 2. How can i forbid the user to access other directories?
Thanks,
Gaurav
Since users should never be aware of the "/hello/" directory-path, it may be as simple as denying any direct client requests for any "/hello/" paths, while still allowing requests to be internally-rewritten to that directory-path:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /hello/
RewriteRule ^hello/ - [F]
GET /hello/192.168.199.2/192.168.199.2_user.html
I'm actually not sure why/how your example URL resolves. I mean, I would expect a 404 error for that URL, even if you wanted to allow access to URLs like it. Turn off MultiViews, mod_speling, and AcceptPathInfo unless you need them.
Jim
Actually i have few links on the pages which can point to hello folder and then IP Folder. I am removing them from page as they are not needed anymore. This will prevent users to guess exact URL.
It was really a great help from your side. This forum is very helpful for IT techies.
Wish you all the best :)
Thanks,
Gaurav Pruthi