Report this

What is the reason for this report?

How do i secure my folders and use mod_rewrite for rewriting URLS

Posted on July 11, 2015

Hello there! I just set up a droplet and so far i’m loving it. But i have two problems thats preventing me to launching my new site. I have a little knowledge of servers and vps servers but i’m not a pro at all haha. The first problem i’m having is that people are able to view my private files. For example they can type this in the url field:104.236.250.72/public/ and they can see everything in there. I cant figure out the mod_rewrite statement to make sure that when people try to access those urls that they are redirected or something

The second problem i have is with my .htaccess. My site is a custom made MVC website and it relies on .htaccess. All of the other pages work except the “index” page. When i type 104.236.250.72/index it gives me a 404 error that it cant find that file. But if i type 104.236.250.72/login it gives me the correct page.

This is how my .htaccess file looks:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?u=$1 [L]
 
</IfModule>

I also used this command in my ssh terminal:

 sudo a2enmod rewrite

If someone can help me with these two problems, that would be great :)



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

This comment has been deleted

Hi there,

In case anyone comes across this in the future, here are the things that I would usually check:

  1. Make sure that the mod_rewrite module enabled Apache using the apachectl -M and looking for “rewrite_module” in the list of loaded modules.
  2. If the module is enabled, you might have to also restart Apache using the sudo systemctl restart apache2
  3. Verify that the .htaccess file in the Joomla directory is correct: https://docs.joomla.org/Preconfigured_htaccess
  4. Ensure that the AllowOverride directive in the Apache configuration is set to “All” for the Joomla root directory. This will allow the .htaccess file to be used:
    <Directory "/home/user/public_html">
    AllowOverride All
    </Directory>
    
  5. Check the error log and access log of the Apache service to see if it provides more information about the issue: tail -100 /var/log/apache2/error.log

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.