htaccess to hide html extention and addThis plugin - html

I am using this htaccess code to hide .html extention on my website, but when doing so addThis share plugin is not working. You can find addThis here: https://www.addthis.com/get/sharing
Is there any workaround for this?
RewriteBase /
RewriteEngine on
RewriteCond %{THE_REQUEST} \ /(.+/)?index(\.html)?(\?.*)?\ [NC]
RewriteRule ^(.+/)?index(\.html)?$ /%1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.+)\.html$ /$1 [R=301,L]
RewriteCond %{SCRIPT_FILENAME}.html -f
RewriteRule [^/]$ %{REQUEST_URI}.html [QSA,L]

It is currently not possible to total share counts for different URLs:
http://support.addthis.com/customer/portal/questions/206634-can-i-total-share-counts-for-two-different-urls-short-and-full-for-the-same-content-
and it's not a problem with the redirect, but an issue with addthis code.
You should have used the redirection code from the beginning.

Related

Only the homepage redirects to www version and not the internal pages. Why?

I am trying to redirect all the requests to https www version of the website. Homepage redirects perfectly fine but any other page of the website doesn't. I checked the redirect rules mentioned in the htaccess and they work perfectly fine. However, on the live website, it doesnt.
Here's the redirect rules
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NC]
Any reason why this is happening?
I tried working through different redirect rules to see which one redirects as per the requirement.
try this
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.yourSiteName.com/$1 [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.yourSiteName.com/$1 [L,R=301]

How to allow a html file to be displayed on a website in htaccess

i've never really played around with htaccess before and can't figure out how I would go about displaying a html file in a folder called "radio" when someone was to go to mydomain/radio. The current code in htaccess is below and came with my website cms when I set it up. Any help is appreciated.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/([^.]+)\.(png|jpg|gif|css|js|otf|ico) [NC]
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) public/$1 [L]
RewriteCond %{REQUEST_URI} !public/
RewriteRule ^ public/index.php [QSA,L]

Website links won't work with .htaccess code which removes .html extension

I have the following code in my .htacess file for my website to remove '.html' from my urls and to redirect any .html to the same page without it (example.com/home.html to example.com/home)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
#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]
However, when I try to click on links that are pointed to other pages on my website, I get a 404 error.
I've tried setting the href to http://www.example.com/page2, /page2 and more but I still get the same error. Any help?
Please save your code and put only the following code in your main directory .htaccess file :
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(.*?)\.html[\s?/] [NC]
RewriteRule (.*)$ /%1%2 [R=302,L,NE]
Note: clear your browser cache because you did 301 redirect and test the code

Links (without /index in them) are not pointing to index of that subdirectory

I've looked for about two hours for a way of solving, this to no avail:
Just to make it easier I'm providing links: malumkose.com malumkose.com/hizmetler
In the main page (first link) there is a button link to the page "hizmetler."
When I was linking these pages to one another, I didn't add in the /index or /index.html extensions to the links, and thought it would work on the server as it did on localhost.
The thing is, my site is peppered with these links - they're all over the joint! I would go and manually change these to add the file extension, but that would only cause the link to direct me to "hizmetler/index" instead of just "hizmetler."
I have tried adding the first line here to my .htaccess file, but it still doesn't point links without index in them, to the indexes of these subdirectories.
`DirectoryIndex index.html
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]`
How could I possibly kill these two birds with one stone?
I don't completely understand the structure for the files of your pages, but this should help for your .htaccess file:
Options +FollowSymLinks
RewriteEngine On
DirectoryIndex index.html
RewriteRule ^hizmetler$ ./hizmetler/index.html
RewriteRule ^something$ ./something/index.html
RewriteRule ^something-else$ ./something-else/index.html
Then it will work as follow:
malumkose.com/ > /index.html
malumkose.com/hizmetler > /hizmetler/index.html
malumkose.com/something > /something/index.html
malumkose.com/something-esle > /something-else/index.html
If you want to force SSL/HTTPS, then add (between the enter of the above script):
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

How to redirect using .htaccess file that redirects from clear domain to www.?

How to redirect:
from mydomain.pl to www.mydomain.pl/start
and
from www.mydomain.pl to www.mydomain.pl/start using .htaccess file?
This should not interfere with any other page. Eg. when somebody types mydomain.pl/contact this should only add www. before the domain.
You can place this rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain\.pl$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.pl$ [NC]
RewriteRule ^$ http://www.mydomain.pl/start [L,R]