I need to point web url's like


to same directory


on Linux hosting (Ubuntu 16.04, Apache2) - how to do that, please? Maybe it can be solved using .httaccess? If not, is there any other option, please?

closed as unclear what you're asking by Mark, Toby Speight, Scott, Pimp Juice IT, TomEus Dec 25 '17 at 18:11

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • First, which one is your webroot directory. I'm assuming /var/www/vhosts/example.com/httpdocs/ , right? If so, subdir1 and subdir2 are inside httpdocs, as well as the default directory. Redirects can be done either through the vhost config file, or throug htaccess. You can use regular expressions to follow some kind of rule when to redirect some directories, to the default directory. – Erlis D. Dec 16 '17 at 20:55
  • Thank you for your analyze, actually subdir1 and subdir2 does not exists, they just need to point to directory /var/www/vhosts/... Yes, .htaccess will be pefect - if you can give me some example, that would be great. – user2666909 Dec 16 '17 at 21:03

Assuming the web root directory is under /var/www/vhosts/example.com/httpdocs/, and you need to redirect any sub-directory to the 'default' sub-directory, you would need an .htaccess rule like the following:

RewriteRule ^subdir.*$ /default/$1 [R=301,NC,L]

You can test your htaccess rule on a site like this one: http://htaccess.mwl.be/
What that site is doing, is checking the Regular Expression you have provided on the first block of the the RewriteRule, and the matched results will get redirected to the path you want to.

Keep in mind that the above rule might not always work, depending on your apache configuration.

You can play with different regex expression by testing the expression on sites like https://regex101.com/

Also a good place to learn about regex is https://www.regular-expressions.info/

  • Thank you for your work but this is not what I need. Your .htaccess forward subdir to default but what I need is to stay on subdir url and to read data and configuration from default. Do you have any example for that, please? – user2666909 Dec 16 '17 at 22:10
  • As far as I can tell, thats not possible with apache, but you can read more here: httpd.apache.org/docs/2.4/urlmapping.html With the apache rewrite rules, you basically redirect a directory or URL to another to make it look cleaner for example, but not get the contents of another directory for different URLs. – Erlis D. Dec 17 '17 at 0:06
  • This works fine in vhost.conf: <IfModule mod_alias.c> Alias /subdir "/var/www/vhosts/example.com/httpdocs/default" </IfModule> how to do that in htaccess, please? – user2666909 Dec 17 '17 at 9:41
  • 1
    Try RewriteRule ^subdir(.*)$ /default/$1 [R=301,NC,L] Alias won't work in .htaccess. But if it works on the apache config, I suggest you use that. Its way better than using htaccess. – Erlis D. Dec 17 '17 at 14:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.