(HTTP) Hide page extension in the URL - html

I'm making a web page using my Raspberry PI and Apache. I made the page chat.html.
To connect to it I have to write in Chrome "http://192.168.1.39/chat.php". How can I hide the '.php'(or anything else) from page URL, so when I connect to "http://192.168.1.39/chat" directly it doesn't give Error 404?
Thank you in advance.

Use URL rewriting by utilizing .htaccess. Basically .htaccess is a file that let's you alter the config of a webserver like Apache.
In your web site root, create a filed called .htaccess.
Paste this in it:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
*.php files can now be accessed the way you describe. For more info on htaccess and url rewriting, please reference http://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/

Related

Redirecting multiple duplicate URLs to main URL using .htaccess

I developed a website and from SEO point of view, the homepage of a website is available under three or more different URLs which accordingly poses a risk of duplicate content, since the same content can be accessed via different URLs.
for eg.
my website is opening with below URL
https://www.insider.in/index.php
https://www.insider.in/
https://insider.in/
Exact URL which is needed be like
https://www.insider.in/
for achieving the same i am using an .htaccess file with code given below:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*index\.(php|html?)[#?]?
RewriteRule ^(([^/]+/)*)index\.(php|html?)$ https://insider.in/$1[R=301,L]
I tried to redirect all duplicate URLs to one URL using the above .htaccess file code but it is not working, also i enabled all the file permissions in FileZilla but again no success.
Any help or reference will be appreciated, thankyou!
note- website is hosted in cloud server using FileZilla
for Reference I am sharing the screenshots
Image of development folder for your reference
Image of .htaccess rule which i have used
You can use the rules below to fix duplicate content issues on your site :
RewriteEngine on
#Redirect non-www domain to www
RewriteCond %{HTTP_HOST} ^insider\.in$ [NC]
RewriteRule ^ https://www.insider.in%{REQUEST_URI} [NE,L,R=301]
#Redirect /index.php to /
RewriteCond %{REQUEST_URI} ^/index\.php$
RewriteRule ^ https://www.insider.in/ [L,R=301]
Remember to put theses rules at the top of your htaccess.

how to remove the url extension

I am developing a website for myself, pure and without server language.
The urls are as they are called in the a tag, for example: blog / index.html.
Is there anything I can use to change that? I don't want to have to use framework. I would like to know if there is any tool that does this.
What I want to change is the ending. I don't want the extension to appear, just the route
try create .htaccess file on your root folder then paste this
#remove html file extension-e.g. https://example.com/file.html will become https://example.com/file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
you can read more about this here https://www.plothost.com/kb/how-to-remove-php-html-extensions-with-htaccess/
EDIT
Since you are using Vercel.com, as per their documentation there's a file config named vercel.json you can add this
{
"cleanUrls": true
}
the docs said,
When set to true, all HTML files and Serverless Functions will have their extension removed. When visiting a path that ends with the extension, a 308 response will redirect the client to the extensionless path.
for more information pls read their docs here https://vercel.com/docs/configuration#project/clean-urls

The URL adds /public_html/ after changes in .htaccess

I'm a newby on using the .htaccess file for making changes on my website.
I want to change a URL automatically by adding the "www." at the begining of the domain name. To do so I enter the following code on the .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.arnaldpedros.com$ [NC]
RewriteRule ^(.*)$ http://www.arnaldpedros.com/$1 [L,R=301]
I see allover the web that this is the proper way to do it but when I type arnaldpedros.com in my browser it takes me to:
http://www.arnaldpedros.com/public_html/
Whis is a 404 Not Found page, with the message:
Not Found
The requested URL /public_html/ was not found on this server.
What I want to do is to type arnaldpedros.com and to automatically go to www.arnaldpedros.com.
It's driving me crazy cause the same happens on many websites I mange.
Any help please?

How can i remove .html from static html website pages

I have a static website with static files (pages), I would like the URLs of the pages not to contain .html at the end, for example:
"www.mywebsite.com/page.html" to become "www.mywebsite.com/page"
of course I can't just redirect the page, since the file "www.mywebsite.com/page" isn't known
Thanks in davance
I would recommend you use URL rewriting for your server's config file.
For example if you are using an apache server, you could use
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html[NC,L]
in your .htaccess file (which is the config file for your apache server.

How do I redirect "website/page" to "website/page.html" when people type it in browser (pretty-url)

I recently started using a static site with godaddy.com without a cms. It's a basic website I uploaded and is only html/js/css.
When people type "website.com/page" they get 404 not found.
When they type "website.com/page.html" they get the correct page.
How can I fix my site so users can simply type "website/page" and not be forced to type "website/page.html" without using php?
SOLUTION
After researching the information about .htaccess files provided by #Gijsberts (thank you), I did the following:
Created a .htaccess file on server.
Added the following code:
# Remove the .html extension from html files
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.html [NC,L]
Most CMS systems have a .htaccess file what handles the redirect and the 404 errors. In CMS system they are most called "Pretty-urls". Read the links below to set up those pretty urls yourself with a static web page without a cms.
https://mediatemple.net/community/products/grid/204643080/how-do-i-redirect-my-site-using-a-htaccess-file
http://code.tutsplus.com/tutorials/using-htaccess-files-for-pretty-urls--net-6049
You normally can do this with your Webserver config. In Apache you have this enabled automatically. In nginx you should have a look at this tutorial.
If you are using caddy you have to config your caddyfile like
ext .html .htm .php
if you are using microsoft iis have a look at microsofts tutorial.
Let me know if you are using something else or need more help.
EDIT
If you are using a webspace you may are not able to change the config of the webserver. you now can use .htaccess. create a .htaccess file and write down something like
Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]