how do i use .htaccess to redirect different languages to different pages? - html

I'm trying to make a simple 2-language site, en and th, I am unfamiliar with .htaccess but found an online tool: http://www.htaccesstools.com/redirection-by-language/
I would like English browsers to go to my root folder's index.html, and Thai browsers to a subfolder.
What I got from the generator is:
RewriteEngine on
RewriteCond %{HTTP:Accept-Language} th [NC]
RewriteRule .* http://www.mysite.com/th/index.html [R,L]
This doesn't work and I get a redirect loop/other error. I've tried changing the url on the last line to be relative, but this doesn't affect it.
Any help?
*to confirm, i have one .htaccess in my root folder only

Try this in your .htaccess file:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_URI} !^(/th/index.html|.*\.(woff|ttf|svg|js|ico|gif|jpg|png|css|htc|xml|txt))$ [NC]
RewriteCond %{HTTP:Accept-Language} ^th [NC]
RewriteRule .* /th/index.html [R,L,QSA,NE]

Related

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]

.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]

How to make .html appear as / in .htaccess

My problem is this,
I want for example:
Make www.mywebsite.com/index.html
Look/appear (not redirect) like this
www.mywebsite.com/index/
so far I used below code and only obtained www.mywebsite.com/index look.
I will highlight that I don’t want to redirect, I want only to the html look like folder
I work in Adobe MUSE. I build websites mostly for fun and just want to focus on designing not coding
Here is my .htaccess script taken from here: .htaccess rewrite /foo/bar/ to /foo/bar.php
Please, can someone help me with it?
What line(s) should I change to have the folder appearance
Thanks
Options -MultiViews
RewriteEngine On
RewriteBase /
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Za-z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.html -f
RewriteRule ^(.+?)/?$ $1.html [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: