Loss of format due to .htaccess - html

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.

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]

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]

redirect subfolder to root with <subfolder-name>.html using htaccess

I have website that has links like
domain-name.com/pages/contact-us/
www.domain-name.com/pages/contact-us/
domain-name.com/pages/about-us/
www.domain-name.com/pages/about-us/
and other pages ...
What I'm looking for how i can redirect them permanently to same subfoldername.html using htaccess . for example for all the links above should redirected to
domain-name.com/contact-us.html
www.domain-name.com/contact-us.html
domain-name.com/about-us.html
www.domain-name.com/about-us.html
also for other pages, otherwise if page not found to root index.html .
Thanks in advance.
Try the following
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(/pages/(.*[^/])/?)$
RewriteRule ^(.*)$ /%2.html [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.html [L,R=302]
The first three lines will remove the folder pages. If there is a trailing slash, it will be removed. The last three lines will redirect to /index.html, if the request file does not exist.

Access CSS file after htaccess modified url

I am using this htaccess file to re-write my urls:
RewriteEngine On
# Friend SEO url
#RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /([^\ ]+)\.php
#RewriteRule ^ /%2/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(.*?)/?$
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule ^ /%1.php [L]
The url rewriting works perfectly fine (for example, mypage/web-store/ can be used instead of mypage/web-store.html).
The problem however, is that my rewritten url can't retrieve the CSS file correctly. If I use the normal url however, I have no problem at all because the CSS file is in a subfolder of mypage. But with the url rewrite, it looks for the css file inside the folder /web-store/, which doesn't exist...
Anyone knows a way to counter this ?
You need to either change your URLs to absolute URLs (add a leading /) or you can set a relative URL base in the header of your pages:
<base href="http://example.com/mypage/" />
Where "example.com" is the domain name of your site and the /mypage/ is where the css is at.
If all else still fails, you can try to rewrite the proper page:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^/]+\.css)$ /path/to/styles/$1 [L,R=301]

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

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]