Htaccess and subdomain issues

July 18, 2016 512 views
Apache LAMP Stack


So I'm having some issues with a subdomain which I can't fix after reading a lot through the internet.

I'm trying to set up an api subdomain which purpose is to respond http requests, so my index file is just a php that redirects to the web (which is working fine).

I have an .htaccess with redirects things like api.domain.tld/createuser to api.domain.tld/api/user/create.php, but it is not working (I'm getting 404 error code). If I do the http request with the long url it works fine.

Also, just in the case it is useful, I've added an info.php to check phpinfo() and I'm getting a 500 error code.

Can anyone help me out?

NOTE: I've already checked:

  • In /etc/apache2/apache2.conf, in directory /var/www AllowOverride All is set.
  • Mod_rewrite is enabled, checked via phpinfo()
  • Does it work when you go to the url directly? api.domain.tld/api/user/create.php

    Also can you post your htaccess and apache config?

  • It does work when I go to api.domain.tld/api/user/create.php.

    Redirect 301 ^/createuser/$ /api/user/create.php

    I cannot post apache config cause I cannot access the droplet right now, but I'm pretty sure it should be right. Tomorrow I'll do it if I haven't found the problem yet.

3 Answers
fncapps July 21, 2016
Accepted Answer

Well, I've finally found the problem. The file /var/run/mysqld/mysql.sock file was missing, I really don't know how or why but I returned to a old snapshot and did things over it and now everything seems to work.

Thanks @MDS for the help, some things were useful for me.

Make sure that you have AllowOverride set to All in your apache virtual host file.

<Directory /var/www>
    AllowOverride All

And change .htaccess to

Redirect 301 /createuser/ /api/user/create.php


My apache2.conf file contains exactly this:

<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied

<Directory /usr/share>
        AllowOverride None
        Require all granted

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted

I've got several Virtual Host files: 000-default.conf, domain.tld.conf, sub1.domain.tld.conf, sub2.domain.tld.conf and in all of them I've got:

<Directory /var/www/url/public_html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted

Where url can be html, domain.tld, sub1.domain.tld or sub2.domain.tld.

Also I've changed the .htaccess as you told me, and stills the same >.<

Thanks for the help

  • Make sure the .htaccess is accessible by apache.

    chown -R www-data:www-data /var/www
    chmod -R 766 /var/www
    • I've tried this but isn't fixing anything.

    • Should I remove 000-default.conf file and only leave the ones I'm using? Maybe that is causing the problem

      • You can try disabling the default config file.

        sudo a2dissite 000-default.conf
        sudo service apache2 restart

        Also where is the .htaccess file located?

        • Nothing happened after having 000-default disabled.

          .htaccess is located under /var/www/url/public_html.

Have another answer? Share your knowledge.