1

Context: How can I configure a NameCheap domain to point to an Apache subfolder?


Following Devin's answer here I've created a .htaccess file in /var/www and wrote in the following:

RewriteEngine On

RewriteCond !sergiotapia.me
RewriteRule (.*) sergiotapia.me/$1 [QSA]

My folder structure is such:

/var/www/
/var/www/sergiotapia.me

When visiting the URL sergiotapia.me I see the contents of /var/www when I would like to be directly redirected to /var/www/sergiotapia.me

Any ideas?

sergserg
  • 119
  • 2
  • 7
  • "When visiting the URL `sergiotapia.me`" - If you actually visit the URL `sergiotapia.me` then no redirect would seem to be necessary? (Assuming the document root is `/var/www`?) – MrWhite Aug 20 '20 at 00:07

3 Answers3

5

From your question, i think you don't need to use rewrites here, but you should change your DocumentRoot within your VirtualHost block to point to the right directory. So for instance:

<VirtualHost sergiotapa.me>
...
DocumentRoot /var/www/sergiotapia.me
...
</VirtualHost>
Wouter
  • 226
  • 1
  • 4
1

Check your virtual host configuration for AllowOverride (Probably within a <Directory /var/www> section).

If AllowOverride None is set then .htaccess is not parsed. Set it to All might help...

MrWhite
  • 12,647
  • 4
  • 29
  • 41
andrekeller
  • 499
  • 2
  • 5
0

A . in a regular expression is a special character (it means "any character except \n"), so you'll need to escape it.

Try:

RewriteEngine On

RewriteCond !sergiotapia\.me
RewriteRule (.*) sergiotapia\.me/$1 [QSA]
Mark Henderson
  • 68,823
  • 31
  • 180
  • 259
  • It still doesn't redirect despite escaping the regex. Do you think I need to restart the Apache service first? Edit: Restarted service and still no dice. :( – sergserg Nov 18 '12 at 21:07
  • "`RewriteCond !sergiotapia\.me`" - this directive is not even valid ("bad argument") and would result in a 500 error if processed at all. – MrWhite Aug 20 '20 at 00:07