How to add pages to a website (cPanel & Apache) - html

I'm very new to web development, and know nothing of back-end dev. I have a website hosted by a 3rd party on a Linux server, using cPanel.
I have a index.html page that is loaded when you go to the website www.domain.com and I have a second file page2.html that loads when I go to www.domain.com/page2.html
Problem 1:
I want to be able to go to www.domain.com/page2 and have page2.html load.
Problem 2:
When I go to www.domain.com/page3.html (which doesn't exist) or www.domain.com/page3 or any other non-existent url index.html loads instead of giving me a 404 error. I have made a custom 404 page (404.shtml) which is in the same directory as index.html and page2.html (/public_html/).
How do I get this 404 page to show when I go to a non-existent URL? I checked the error log on cPanel and it shows a File does not exist error.
[Fri Aug 29 20:16:48 2014] [error] [client ...*] File does not exist: /home/adminName/public_html/page3, referer: http://domain.com/page3/
Any pointers in the right direction would be very helpful.

To remove the suffix (.html) from your url, you would need to use .htaccess.
The following will first check if the request is a file (images/css etc.) or directory, then serve the file without the suffix.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
The following will serve a custom 404 error document
ErrorDocument 404 /404.shtml

I just found a similar StackOverflow Question for Problem 1, and the second answer, by Ɓukasz Habrzyk, worked for me.
#example.com/page will display the contents of example.com/page.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]
#301 from example.com/page.html to example.com/page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=301,L]

Related

htaccess 404 loop - internal server error

I am a newbie here, made an htaccess with 301 redirect pages with extension (.html) to have no extension. The thing is that when entering into a wrong directory path the 404.html page doesn't work probably because a loop: It displays an error
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at webmaster#pesto.com.uy to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
The htaccess file is as follow:
DirectoryIndex index.html
RewriteEngine On
RewriteRule ^index\.html$ / [R=301,L]
RewriteRule ^(.*)/index\.html$ /$1/ [R=301,L]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} !rewrited
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ $1.html [NC,L]
ErrorDocument 404 /404
ErrorDocument 500 /404
Any ideas why this happens?
Warm regards guys

htaccess , can't access homepage

I'm trying to set locally a project that run on the web on a NGIX server. This is the htaccess i have downloaded:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~sitename/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~sitename/index.php [L]
</IfModule>
I'm trying to run it locally on an Apache server(on mamp) . It have placed the project in a folder on the server root:
http://localhost/sitename/
But i get a blank page.
I can access a specific internal page (and only that one) if i remove the tilde
~
Even without the tilde, i can't access the homepage of the project.
So what i'm doing wrong?
How the tilde works in this context ?
EDIT
my mod_rewrite is loaded/enabled

A really weird .htaccess issue

So let us say that my website is www.example.com and I have a contact.html page in the root. The URL normally shown in the address bar is: http://example.com/contact.html
For my site, I want the URL to have:
no www
no .html
a trailing slash
So the final result should look like this: http://example.com/contact/
Condition No. 1 is default, so that doesn't bother me.
For Condition 2 (no '.html'), I have the following code into my .htaccess file place in the root directory:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
...and it works perfectly.
Now coming on to Condition 3 (enforcing trailing slash), I have the following code into the .htaccess file before the 'Condition 2' rewrite commands:
RewriteEngine On
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
...this does not work; The page redirects to the Error 404 page and the address bar shows: http:/example.com/404.html... YES, with the trailing slash :/
What am I doing wrong?
I have a folder called archives in the root directory of which I want indexing to be done. So I simply added a .htaccess file in the 'archives' folder and added the following, simple code:
Options +Indexing
But it doesn't work; I get redirected to the Error 403 page! I'm 99% sure that it is due the .htaccess file in the root directory.
Try with:
RewriteEngine On
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.+) %{REQUEST_URI}/ [R=301,L]
# remove html
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^([^\.]+)/?$ $1.html [NC,L]

getting html5 boilerplate .htaccess file to work on dreamhost site

Completely new to Apache.
Trying to remove ".html" extension from urls by adding the following lines (found here):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
to this (including ^ those lines now):
<IfModule mod_rewrite.c>
RewriteEngine On
# Enable the `FollowSymLinks` option if it isn't already.
# Options +FollowSymlinks
# If your web host doesn't allow the `FollowSymlinks` option, you need to comment it out or remove it, and then uncomment the `Options +SymLinksIfOwnerMatch` line, but be aware of the performance impact.
# Options +SymLinksIfOwnerMatch
RewriteBase /
# RewriteOptions <options>
RewriteCond %{HTTPS} =on
RewriteRule ^ - [env=proto:https]
RewriteCond %{HTTPS} !=on
RewriteRule ^ - [env=proto:http]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
</IfModule>
But the .html extensions remain in the visible urls.
I couldn't find any info on whether Dreamhost allows FollowSymLinks, but I tried it enabled, as well as SymLinksIfOwnerMatch, I also tried disabling RewriteBase / and even removing the mod rewrite if statement. I'm placing the file in my website's root directory, and tried placing it in the parent folder to that too with no results. Anybody have an idea what I'm doing wrong?
The full .htaccess is here.
Solved:
I still don't know why the above code didn't work, but I just used the code from Dreamhost's wiki instead:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\ HTTP/
RewriteRule ^(.*)index$ http://Your_Site_Url_Goes_Here.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://Your_Site_Url_Goes_Here.com/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.+)\.html\ HTTP/
RewriteRule ^(.+)\.html$ http://Your_Site_Url_Goes_Here.com/$1 [L,R=301]
RewriteRule ^([a-z]+)$ /$1.html [L]
</IfModule>
Be mindful that the above code may cause new problems, as it is causing one of my pages to return a 403 Forbidden error, but I think that's a whole other problem irrelevant to my original question so I consider this a solve and will fix the above code when I find a solution elsewhere.
Symlinks seem to have been irrelevant.
.htaccess file goes in >mySite.com directory, rather than the directory that contains this directory
DreamHost wiki has a guide on how to use Apache redirects and rewrites. The guide mentions FollowSimylinks
You should also check the Apache error logs to see what fails (and edit your question to be more specific about the result you see in the browser).

After 5 to 5.1 SQL upgrade 500 internal server error

It's on a site that uses symlink - not sure if that's to blame.
I upgraded from SQL 5 to 5.1.
Several sites failed due to the htaccess saying php rather than php5 but that was simple to fix, one site is proving more difficult and I can't seem to find an answer.
The index.php page is actually static html so I'm thinking it must be the .htaccess at fault for this showing a 500 internal server error.
The .htaccess file looks like this:
Options -Indexes +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^(\.cache|images|cgi-bin|ads|css|vids|theme) - [L]
RewriteRule SteelExternalAll\.swf$ /theme/skin-SteelExternal.swf [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/[^/]+/(play-|index\.)
RewriteRule ^(games|videos|animations)/([^/]+)/? /$1/play-$2/ [NS,R=permanent,L]
ErrorDocument 404 /index.php