Forum Moderators: phranque
I need everything written after the / to be read as if it had the ~
I have many users in the /home folder but in order to see them I need to use the ~ and I don't want to force the user to use the ~
I also wonder, where would I put that ruler? httpd.conf? I need this to be true for all folders inside /home
and not, im not using otrer mod_rewrite directive
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]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /~mysite
RewriteRule (.*) http://example.com/$1 [R=301,L] Perhaps I should not be reading this so close to bedtime, but wouldn't this simply go around in circles? Unless you include the same RewriteCond as in the second rule. the code i assume you tried as a starting point was this?
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]
(you should post an exemplified version of the code you tried)
this code will return an external 301 redirect of the request for the tilde url to the non-tilde url.
this is something that i would also suggest you need.
however it doesn't do the internal rewrite you need from the non-tilde url to the tilde url.
show us what you tried and we'll start from there.
The question phranque has asked several times, and it’s absolutely essential to get an unambiguous answer, is:
Are there any URLs whatsoever that do not begin in ~ (tilde)? (Supporting files such as images and stylesheets don’t matter, because those can be exempted by other means.) You need to make sure you are not rewriting or redirecting URLs that aren't supposed to have a ~ tilde in the first place, such as /contact or /legal
But as I type this, I note that the examples are consistently in the form
example.com/user
and-that's-all. That means you cannot simply rewrite (or redirect, doesn't matter) to
example.com/~user
because that is still not a physical file.
Are these actually directories in the form
example.com/~user1/
example.com/~user2/
and so on?
This leads to the tangential question: If your users are likely to type in the URL without the leading ~ tilde, what is the tilde for? Casual research suggests it's going out of style anyway, with the possible exception of academic sites.
im using mod_userdir in the server and for that i need to put ~ (tilde) to go to the user folder ( example.com/~user1 )
This module allows user-specific directories to be accessed using the http://example.com/~user/ syntax.
RewriteEngine On
# this should 301 redirect any requests for /~user/ to https://example.com/user/
RewriteRule ^/~([a-zA-Z0-9]+)/$ https://example.com/$1/ [R=301,L]
# this will redirect any non-secure requests or any requests for subdomains (including www) to the https://example.com hostname
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^(example\.com)?$ [NC]
RewriteRule ^(.*)$ https://example.com$1 [R=301,L] this should handle redirects of any requests for non-canonical hostnames and for users' directories containing the tilde.
the regular expression for matching a user name pattern may need some tweaking.
once that is working there will likely be additional tweaks needed to handle the contents of user name directories.
whether or not an internal rewrite is required to translate the requested path depends on what your UserDir directive looks like.
i'm not even sure it would work - it probably depends on the order of module execution, so this would take some testing.
at that point, i'm wondering why you're jumping through hoops to use mod_userdir while trying to avoid the tilde usage.
you can probably do it all with mod_dir.
are you using UserDir (dis/en)abled keyword directives?
I'm wondering where to put this code.
httpd.conf?
when I create accounts to access those accounts I must use the ~ parameter
I tried to disable mod_userdire to see if that could open users without the ~ parameter but nothing.
What I have thought simply by searching many places is to keep the mod_userdir but looking for the way you suggest that when entering through /user1 it passes through /~user1 but actually opens the real content that is in /user1
the patterns specified in the RewriteRule Directives assume these directives are in httpd.conf, as discussed earlier.
what does your UserDir directive(s) look like?
"nothing"?
no response?
no clues in the log files?
you should be looking for content in https://example.com/~user1/ (a directory url) and not https://example.com/~user1 (no trailing slash)
what happens when you request this?
https://example.com/user1/
[edited by: phranque at 9:24 pm (utc) on May 12, 2022]
[edit reason] please exemplify domains [webmasterworld.com] [/edit]
<IfModule mod_userdir.c>
UserDir disabled
UserDir enabled instru1
</IfModule>
User directory substitution is not active by default in versions 2.1.4 and later. In earlier versions, UserDir public_html was assumed if no UserDir directive was present.
<IfModule mod_userdir.c>
UserDir disabled
UserDir enabled instru1
</IfModule> i don't see anything that specifies user directory locations for translation.
where does this (/instru1/) directory actually exist?
what is the DocumentRoot directive's specified directory path?
It's explained a little more coherently in the tutorial [httpd.apache.org] (though not a lot more coherently).
Key point: there's a line missing from the UserDir directives. In addition to the disabled/enabled lines which specify what users are allowed, there also has to be a line setting the physical filepath(s) for all those example.com/~username/blahblah URLs.
It would admittedly be more intuitive if there were two different directives--one to spell out the users, one to declare the filepath--but it can't be helped.
# Settings for user home directories
#
# Required module: mod_authz_core, mod_authz_host, mod_userdir
#
# UserDir: The name of the directory that is appended onto a user's home
# directory if a ~user request is received. Note that you must also set
# the default access control for these directories, as in the example below.
#
UserDir https://hosting.example.com/*/
#
# Control access to UserDir directories. The following is an example
# for a site where these directories are restricted to read-only.
#
<Directory "/home/*/public_html">
AllowOverride FileInfo AuthConfig Limit Indexes
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Require method GET POST OPTIONS
</Directory>
AliasMatch
When not to use mod_rewrite
mod_rewrite should be considered a last resort, when other alternatives are found wanting. Using it when there are simpler alternatives leads to configurations which are confusing, fragile, and hard to maintain. Understanding what other alternatives are available is a very important step towards mod_rewrite mastery.
Simple Redirection
mod_alias provides the Redirect and RedirectMatch directives, which provide a means to redirect one URL to another. This kind of simple redirection of one URL, or a class of URLs, to somewhere else, should be accomplished using these directives rather than RewriteRule.
when there are Redirect and RewriteRule directives in the same scope, the RewriteRule directives will run first, regardless of the order of appearance in the configuration file