Redirecting multiple duplicate URLs to main URL using .htaccess - html

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.

Related

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?

Broken images on CodeIgniter website after uploading to server

I uploaded my CodeIgniter website to the server, but after uploading the website layout is not working properly. Some images work, but other images are not showing.
My .htaccess file:
RewriteEngine On
RewriteBase /beta
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css|docs|js|system)
RewriteRule ^(.*)$ /beta/index.php?/$1 [L]
The base URL in config/config.php:
$config['base_url'] = 'https://www.lalcoresidency.com/beta/';
Here is my website link: https://www.lalcoresidency.com/beta/
There are several things to check that will help you trouble shoot.
The very first thing to do is to confirm that the image folders and files are actually on the server.
Try to figure out what the missing images have in common. Are they all in the same folder? If so, are permissions for that folder and its files set appropriately?
The owner of the folder(s)/file(s) will also need to be set appropriately. This will depend on the server. Many Apache based servers have the owner set to www-data.
Are any of the images loaded through css? For example, background-image: url("images/ui-icons_444444_256x240.png")? If so, confirm that the css file(s) are actually loading. Your browser's development tools will be invaluable for this. (Firefox uses Firebug and Chrome uses Web Developer)
I don't see any obvious problems with your .htaccess file.

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]

(HTTP) Hide page extension in the URL

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/

Redirect non-existant site pages via .htaccess

I have a problem right now with visitors browsing to pages that used to exist on my server but no longer. This is due to my initially poor decision to use a subdirectory instead of a subdomain. Because of this, people posted direct links to the pages themselve instead of the directory to various message boards. So when people Google and find links to my site, they click what the people have linked and it directs them to a "Not Found" page.
To better explain, here is my best attempt at giving an example.
The main URL people were using to visit my site was hxxp://example.com/subsite/. Within that /subsite/ directory there were files such as welcome.html, about.html, contact.html. So what happened is that when people started spreading my website links around, they would spread a link such as hxxp://example.com/subsite/welcome.html instead of just hxxp://example.com/subsite/. As of right now, the subsite directory only has (mainly) an index.html file.
What I am trying to accomplish is that whenever someone tries to navigate to any webpage within that subdirectory that doesn't exist, it redirects them to the index.html file. I'd like to accomplish this via the .htaccess file.
I attempted to do this myself by using the below code, but apparently I'm too new to how the .htaccess and apache modules work and the below code causes a constant redirect loop.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ hxxp://example.com/subsite/ [L,QSA]
</IfModule>
If anyone has any input, or needs me to clarify any information just let me know. Any help would be greatly appreciated. Thank you!
You can use:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(subsite)/.+$ /$1/ [L,NC,R=301]