: Have UserDir enabled but also want to rewrite url if called differently I am setting up a new server for our users to use have have personal webspace on. I have in my httpd.conf of apache
I am setting up a new server for our users to use have have personal webspace on. I have in my httpd.conf of apache the directives for UserDir as follows
UserDir disabled root
UserDir public_html
This has allowed myserver/~user/ requests to work but I am also looking to set it up so the pages can be accessed via myserver/users/username.
How can this be done? I had thought about mod_rewrite rule but have thus far been unsuccessful.
EDIT:
Essentially I am looking to take the myserver/users/username requests and either point them or rewrite them to myserver/~user/. whether it changes in the address bar is irrelevant at this time.
More posts by @Holmes151
2 Comments
Sorted by latest first Latest Oldest Best
I have consulted some older colleagues of mine and we have found that the rule I was looking for was:
RewriteRule ^/users/(.*)$ /~ [R]
If I were using Alias matching I would need:
AliasMatch (^[A-Za-z0-9])
Here is somebody that managed to use rewrite rules to remove the tilde completely: www.bit-integrity.com/2011/08/getting-rid-of-tilde.html
I've modified what they did to put the "users" directory in.
RewriteEngine On #RewriteLog logs/rewrite.log # Uncomment for rewrite logging #RewriteLogLevel 3 # uncomment for verbose logging
RewriteCond %{REQUEST_URI} ^/users/([^/]+)
RewriteCond /home/%1 -d
RewriteRule ^/([^/]+)(.*) /home//public_html/
Here is a thread at WebmasterWorld.com where somebody wanted to redirect away from the version with the tilde: www.webmasterworld.com/apache/4362132.htm
If you wanted to redirect away from the tilde version, you would have to use something like this. These rewrite rules are meant to go into each users .htaccess
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /~mysite
RewriteRule (.*) example.com/ [R=301,L]
RewriteCond %{HTTP_HOST} !^(example.com)?$
RewriteRule (.*) example.com/ [R=301,L]
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2025 All Rights reserved.