Have UserDir enabled but also want to rewrite url if called differently
Solution 1
I have consulted some older colleagues of mine and we have found that the rule I was looking for was:
RewriteRule ^/users/(.*)$ /~\$1 [R]
If I were using Alias
matching I would need:
AliasMatch (^[A-Za-z0-9])
Solution 2
Here is somebody that managed to use rewrite rules to remove the tilde completely:
http://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/$1/public_html/$2
Here is a thread at WebmasterWorld.com where somebody wanted to redirect away from the version with the tilde: http://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 (.*) http://example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^(example\.com)?$
RewriteRule (.*) http://example.com/$1 [R=301,L]
Related videos on Youtube
Spartan-196
Formerly a student at Northern Kentucky University (NKU) Graduated with a bachelors in Computer Information Technology with minor in Computer Forensics in 2014. Considering graduate school for a masters degree. Studying for CCNA and CEH in free time. Also manage and tinker in a homelab environment with enterprise server and network equipment.
Updated on September 18, 2022Comments
-
Spartan-196 about 1 year
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
http://myserver/~user/
requests to work but I am also looking to set it up so the pages can be accessed viahttp://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
http://myserver/users/username
requests and either point them or rewrite them tohttp://myserver/~user/
. whether it changes in the address bar is irrelevant at this time. -
Spartan-196 almost 11 yearsThe first part looks like what I need however it does not appear to be working as intended. I am still trouble shooting it but as of currently writing it does not rewrite
http://myserver/user/test/index.html
tohttp://myserver/~test/index.html
it just states the page cannot be found -
Stephen Ostermiller almost 11 yearsI put in
/users/
not/user/
. Also that rewrite rule is meant to work in your httpd.conf file not in a .htaccess file because the rules start with /, make sure you are putting the rewrite rules in httpd.conf and restarting the server. -
Spartan-196 almost 11 yearsThat was a typeo on my part. I am using
/users/
Nothing is being logged to the log and browsers just return a 404The requested URL /users/test/index.html was not found on this server
-
Stephen Ostermiller almost 11 yearsThats as much help as I can provide then. I hope you get another answer that works for you.
-
Spartan-196 almost 11 yearsI think it is still the right path. Thank you for your assistance. IF I could up vote I would.