Getting wrong display when i add www to my domain name - html

Whenever i add "WWW" to a page on my website, it erases some of the css of that page. but if i load the page without adding the "WWW." prefix it displays properly. Pls help

You could redirect your site to to go the non www.-site, with this redirect:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
If you add that code to your .htaccess people will get redirected to http://yourdomain.com when they enter http://www.yourdomain.com

Related

.htaccess: remove .html and redirect slash version

On my site, all pages have .html extension and are directly off the root (i.e., site.com/page.html). I've successfully used the following .htaccess code to make .html not show:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
This gives me a url like site.com/page, but in the event that a user links to or visits the url using a slash (i.e., site.com/page/), I'd like to 301 redirect to the non-slash version.
I'm having trouble integrating this part into the above code. Thanks in advance for any suggestions.
Try to something like this
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]

Force Trailing Slash + Remove .html and website keeps loading error

I am having problem with adding trailing slash end of URL. I have tried many suggestions from overall web but came up with no successful outcome. Hiding .html works fine, however adding slash does not really work. Main issue is that after I apply code below, the slash appears but website or any page gets never loaded. It keeps in loading mode. I would appreciate if someone helps me through.
My code in .htaccess is:
ErrorDocument 404 /thanks.html
Options -Indexes
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^/]+)/$ $1.html
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.]+\.html(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.html$ http://%{HTTP_HOST}/$1 [R=301,L]

Making a resource (like a pdf) available only if its URL is called from a certain page

I have a pdf file (myFile.pdf) and an HTML page (myPage.html) which contains the following markup:
<a href='myFile.pdf'>Click here to view PDF</a>
Is there a way to make so that the pdf is ONLY reachable when clicking on the link contained in myPage.html and in all the other cases the user gets a redirect to myPage.html ? It's different from hotlinking because it should also prevent direct accessing the URL by typing the address of the PDF. The most similar problem I found so far is here but it does not fully apply to this particular case.
Cheers!
Try this:
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://www\.domain\.com/.*
RewriteCond %{REQUEST_URI} ^/myPage.html
RewriteRule .*\.pdf - [L]
RewriteCond %{HTTP_REFERER} ^http://www\.domain\.com/.*
RewriteCond %{REQUEST_URI} !^/myPage.html
RewriteRule .*\.pdf /your_page [R,L]

Loss of format due to .htaccess

I'm making a .htaccess for my web page, here's the code:
Options -Indexes
RewriteEngine On
RewriteRule ^([A-Za-z]+)/([0-9]+)/$ files.php?row=$1&column=$2
RewriteRule ^([A-Za-z]+)/?$ $1/1/
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mywebpage\.at [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} ^http://.*$
RewriteRule \.(jpe?g|gif|bmp|png)$ /imgs/hotlinks.png [L]
RewriteCond %(REQUEST_URI) ^imgs/$ [NC]
RewriteRule / - [F]
ErrorDocument 404 /404.html
ErrorDocument 403 /403.html
The problem is, my images are not showing up in pages with rewritten URLs. Apparently, their routes are also affected by the rewriting. Simply explained: an image located at www.mywebpage.at/imgs/pic1.jpg loads on www.mywebpage.at/files.php?row=first&column=3, but when I try to enter www.mywebpage.at/first/3/ the browser looks for the image in www.mywebpage.at/first/3/imgs/pic1.jpg, and obviously fails to load it.
How can I fix this so that the routes of the images do not change, no matter from where I use them?
You can do:
RewriteCond $1 !^(imgs)
RewriteRule ^([A-Za-z]+)/([0-9]+)/$ files.php?row=$1&column=$2
That will rewrite everything except the imgs folder.
Edit: Apologies, misread question.
Make your image paths absolute. E.g. relative path is:
imgs/image1.jpg
Absolute path is:
/imgs/image1.jpg
The slash at the beginning tells it to go to the very root of the site and then go to imgs, then image1.jpg.

Redirecting old .html page to new without html extension page?

I've just changed permalinks in my wordpress site.
And my old links were like that,
http://www.sitename.com/category/postname.html
Now new links are
http://www.sitename.com/category/postname/
I'm getting 404 error at old links, how can i redirect all .html pages to new non .html pages with .htaccess?
In the htaccess file in your document root, add these before your wordpress rules:
RedirectMatch 301 ^/([^/]+)/([^/.]+)\.html$ /$1/$2/
RedirectMatch 301 ^/([^/]+)/([^/]+)/([^/.]+)\.html$ /$1/$2/$3/
Of if you need to limit it by hosts, you can use mod_rewrite:
RewriteCond %{HTTP_HOST} sitename.com [NC]
RewriteRule ^([^/]+)/([^/.]+)\.html$ /$1/$2/ [R=301,L]
RewriteCond %{HTTP_HOST} sitename.com [NC]
RewriteRule ^([^/]+)/([^/]+)/([^/.]+)\.html$ /$1/$2/$3/ [R=301,L]
In the htaccess file, just put:
Redirect 301 /postname.html http://www.sitename.com/category/postname/
The accepted answer (above) from Jon Lin caused some issues for me.
This is my result, which works well, and is a bit more compact.
It works for both, with and without directories in the path.
Oneliner:
RedirectMatch 301 ^/(.*)\.html$ /$1
Or if you need it limited by host:
RewriteCond %{HTTP_HOST} myDomain.com [NC]
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
Example: