: Where/how to put .htaccess files? I am trying to update/create a .htaccess file for my apache2 server so that my webpages can be accessed without file extensions (e.g. www.example.com/whatis.php
I am trying to update/create a .htaccess file for my apache2 server so that my webpages can be accessed without file extensions (e.g. example.com/whatis.php can now be accessed as example.com/whatis/). I have tried following instructions on editing .htaccess and now created a .htaccess here:
/etc/apache2/sites-available/.htaccess
I tried reading up on .htaccess files here: httpd.apache.org/docs/2.2/howto/htaccess.html http://wiki.apache.org/httpd/Htaccess
But I didn't find the docs helpful. My understanding is I have to put a file named ".htaccess" at each level/directory where I want to give the server specific instructions. So since I want the server to cut off the .php extension of all files, I created the .htaccess file at the location above and put this inside it:
RewriteEngine on
RewriteRule ^([^/.]+)/?$ .php [L]
However even after restarting my apache2 server, I still cannot shorten the pathname - if I try to load the pathname minus the .php, the page is not found. I am guessing the problem is with my .htaccess file rather than the code.
So long story short, where should I put my .htaccess file and how do these work in general? If there's a recommended resource out there, I'm interested. Thank you.
More posts by @Sarah324
1 Comments
Sorted by latest first Latest Oldest Best
You should place the .htacess file at /var/www/html.
If you don't have a html folder place it in www directory.
Before that you need to change some other configurations. Since you need to enable url rewriting you should first enable it. This can be done by the following command.
sudo a2enmod rewrite
Then you should change the Apache default configuration file.
Open this file by entering
sudo nano /etc/apache2/sites-available/default.
Once inside that file, find the following section, and change the line that says AllowOverride from None to All. The section should now look like this:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
After you have completed this, restart the apache server by the following command
sudo service apache2 restart
This should do the job.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.