I know there are more questions and answers about that but none of them was usefull to me.
I just configured my website on a apache linux server,that I'm managing with cPannel.And I edited my .htaccess file to remove html extensions from my url. But after I uploaded it to File manager , nothing changes.What do I need to do to make it work ?
I've been searching for configuration files to set AllowOverride All but I didn't found anything.And also I don't have etc/apache2/ directory in my file manager, there are other files in etc/ directory.
EDIT: Server info :
Hosting Package:Startup2013
Server Name: wolf
cPanel Version: 11.50.1 (build 3)
Theme: paper_lantern
Apache Version: 2.4.16
PHP Version: 5.6.12
MySQL Version: 5.6.23
Architecture: x86_64
Operating System: linux
Shared IP Address: 185.81.0.40
Path to Sendmail: /usr/sbin/sendmail
Path to Perl: /usr/bin/perl
Perl Version: 5.10.1
Kernel Version: 2.6.32-573.3.1.el6.x86_64
Here is my .htaccess code :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
I assume that you're not running an ubuntu server, that's why you don't have /etc/apache2 directory.
Try this:
Edit the httpd.conf file in /etc/httpd/conf/httpd.conf and set the AllowOverride All
then: apachectl restart
If this doesn't work please run: cat /etc/*-release and show us the output, so we can know which linux distribution you are running.
EDIT: .htaccess was working fine, OP wanted to remove .html extensions
This is the .htaccess you need in order to remove .html extensions:
RewriteEngine On
RewriteBase /
#Removes .html extension
RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.html\sHTTP/.+
RewriteRule ^(.+)\.html $1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Related
I've developed a tiny app in a hosted server via cPanel, by using node js with express and mysql.
so when the app is running via node or forever, it is accessible only when I add the port number in the url. but when the url is without the port, it goes to an Index of the files in the folder of the subdomain. and everyone can view the app.js file including the password to mysql and user name etc...
I thought js files are not accessible or viewable to the client??
what am i doing wrong?
Create ".htaccess" file in the root of your project with following content
RewriteEngine On
RewriteRule ^$ http://127.0.0.1:XXXX/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:XXXX/$1 [P,L]
Where the "XXXX" is the port, that you're using.
I'm new to laravel. It's really good application. I developed web application using laravel docs. But the problem is how to deploy it on live server.
In local development environment we use "php artisan serve" command and can access project from http://localhost:8000.
But what should be proper way to run it on live domain. Please don't suggest me something like copy htaccess to root directory and rename server.php to index.php etc.
I will suggest you to watch video from Youtube videos : Move Laravel to Live
This video help you to install to server ; after installing you may even just ise composer or by copying files to server you can run your project in your live server.
Just be sure you installed laravel .
Of problem exists please let me know.
This .htaccess file will point to public/index.php file
DirectoryIndex public/index.php <IfModule mod_rewrite.c><IfModule mod_negotiation.c>Options -MultiViews</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ public/index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]</IfModule>
I have a domain say abcdefgh.com hosted on Hostgator Cpanel VPS Server. It has a folder inside public_html/abcdefgh.com.
Below are the images of deploying my yii2 website but I am unable to get the result on website.
I had previously deployed the Yii2 applications on shared hosting the same way copy pasting the folder, but here in VPS server, I am curious to know what is wrong in this?
1. Hostgator Cpanel VPS Server Deployment
2. Output
3. Server Error Log
Mon Apr 17 22:48:01.706049 2017] [autoindex:error] [pid 32221] [client 117.208.9.75:49825] AH01276:
Cannot serve directory /home/abc/public_html/abcdefgh.com/: No matching DirectoryIndex
(index.php,index.php5,index.php4,index.php3,index.perl,index.pl,index.plx,index.ppl,index.cgi,index.jsp,index.js,index.jp,index.phtml,index.shtml,index.xhtml,index.html,index.htm,index.wml,Default.html,Default.htm,default.html,default.htm,home.html,home.htm) found, and server-generated directory index forbidden by Options directive
.htaccess file
Options -Indexes
# Rewrite engine
RewriteEngine On
# condition with escaping special chars
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
Delete this from the .htaccess file:
Options -Indexes
Save file and try again!
I have a site I'm making with purely static html pages and I'd like to not have the .html extension on the webpages. I've read dozens of links with different ways to edit the .htaccess file to rewrite urls without the extension, but with no luck.
The strange thing is, I had the .htaccess file on my other site (bradleyoesch.com) and I can access pages without .html at the end (e.g. bradleyoesch.com/projects). However, I deleted the .htaccess file on that site and it still works (bradleyoesch.com currently has no .htaccess file), suggesting to me that I did something else two years ago to get it to work, or I need to restart something to pick up the changes (I've restarted apache on both servers with sudo service apache2 restart).
What am I missing or forgetting to do, or otherwise why would my .htaccess changes not work? My current .htaccess file contents are below.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Ok here's what finally worked. There were some edits to apache2 files I needed to do to get everything to work together. This assumes you're running apache2 version 2+ on your server with some form of linux.
Edit /etc/apache2/sites-available/000-default.conf to have the following lines, just append them to the end (I put them after this line: # vim: syntax=apache ts=4 sw=4 sts=4 sr noet).
<Directory /var/www>
Options Indexes FollowSymLinks Multiviews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Create or edit the .htaccess file in your root html directory (mine is /var/www/html and note the similar directory path above) with the following lines:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
When you make any changes to an apache2 conf file, you have to restart apache2, and if you have not yet, you want to create some symlinks with a2enmod. Otherwise just restart apache2.
sudo a2enmod rewrite && sudo service apache2 restart
You do not need to restart anything when making changes to .htaccess. An easy way to check if it's loading .htaccess at all is to type gibberish in there to force a syntax error, then your pages will 500 error.
With rewrite rules you can use MultiViews to allow Apache to load pages with .html or .php extensions. Just use this line in your Apache config or site root .htaccess:
Options +MultiViews
I realize there is another post about how to remove .html but it is not working for me so I am trying to understand a little better how this process works.
I have fatcow for my hosting service. I downloaded the .htaccess from fatcow and it downloaded at a .htm file. I inserted this code via notepad.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ $1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+)/$ $1.html
</IfModule>
I saved the file as .htaccess and uploaded it to my root folder on fatcow. It is now saved in my root folder as .htaccess.txt
What am I doing wrong here to where this is not working?
UPDATE:
I renamed the .htaccess.txt to .htaccess via FTP client. It shows up at .htaccess now but it is still not removing the .html from my urls.
It should be saved as .htaccess, not .htaccess.txt.
It might be named this way because you created the file on Windows. If this is the case, you have two options:
Upload, then rename
Once the file is uploaded to the server, you can most likely rename the file to have the correct name.
Rename, then upload
You can rename it by doing the following in the Command Prompt:
cd C:\Directory\With\File\In\It
rename .htaccess.txt .htaccess
Once that is done, it should be named .htaccess properly, and can be uploaded.