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?

1
  • "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 0:07
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>
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...

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]
2
  • 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 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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