Htacess Multi language - .htaccess

Im trying to do a multi language errordocument on my htaccess.
But it doesnt enter to my original 404 error page or it just only goes to one of the error pages.
i just want to check the folder and if the folder is "pt", it goes to the portuguese 404error page, else it goes to the other pages with the correspond language.
i already tryed more example but non have help me.
In below there some code that i had already tryed.
Try #1
ErrorDocument 404 http://www.teleondagroup.com/novosite/Teleonda/
RewriteRule ^([a-z]{2}) $1/404error.php [L]
Try #2
RewriteRule ^(pt)/ /$1/404error.php [R,L]
ErrorDocument 404 http://www.teleondagroup.com/novosite/Teleonda/pt/404error.php
RewriteRule ^(en)/ /$1/404error.php [R,L]
ErrorDocument 404 http://www.teleondagroup.com/novosite/Teleonda/en/404error.php
I already solve the problem with this site.
https://webmasters.stackexchange.com/questions/47974/separate-404-page-for-subdirectory

You can use something like the following :
RewriteEngine on
#if a file or directory doesn't exist in a particular folder
RewriteCond %{DOCUMENT_ROOT}/$0 !-f [OR]
RewriteCond %{DOCUMENT_ROOT}/$0 !-d
#redirect the request to /errorpage.php in that folder
RewriteRule ^([^/]+)/.*$ /$1/errorpage.php [L,R]
This will Redirect a 404 Uri to /errorpage.php file located in the requested directory ie . example.com/demo/brokenlink.php to example.com/demo/errorpage.php .
Or if this is just for a single directory /pt you can use the following :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?pt.*$ /pt/errorpage.php [L,R]

Related

Magento2 how to remove %2f from URL

When we are hitting the URL domianname/customer/account/login/%2f we are getting plain page instead of 404 Page without Header and footer
we have try with .htacess by adding
RewriteCond %{QUERY_STRING} ^(.*)((%2F)*)
RewriteRule ^(.*)$ %{REQUEST_URI}? [R=301,L]
still showing same result
also we have try
Added
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ (/.*)\.php
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} !^/error\.php
RewriteRule . - [R=404,L,NS]
ErrorDocument 404 /error.php?e=404
is there anything need to be done at server level ? or it can be handle through .htaccess ?
[1]: https://i.stack.imgur.com/qycvk.pngenter code here

htaccess 404 page for specific subdirectory only (static html pages)

Stuck again with htaccess. How can I add a 404 page to a specific subdirectory?
In my case the 404 page should only affect the "staging" subdirectory (and the directories inside of staging) but not the root or any other subdirectories placed in root.
http://example.com/staging
The code which is in my .htaccess file for the directory "staging":
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ $1.html [L]
Options -Indexes -MultiViews
RewriteEngine on
RewriteRule ^arbeiten/$ /staging/arbeiten/alle [R=301,L]
RewriteRule ^journal/$ /staging/journal/journal-alle [R=301,L]
ErrorDocument 404 /staging/404.html
Using the code above (and many others) results in a Internal Server Error.
Update #1 to my initial question.
In general, the code/answer provided to add a 404 not found page to a specific sub directory works:
ErrorDocument 404 /staging/404.html
The reason why it still does not work is because there must be some error in the overall .htaccess setup related to the code remove .html extension and/or redirect to a page in a folder.
Options -Indexes -MultiViews
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ $1.html [L]
RewriteRule ^arbeiten/$ /staging/arbeiten/alle [R=301,L]
RewriteRule ^journal/$ /staging/journal/journal-alle [R=301,L]
ErrorDocument 404 /at/404.html
I will continue to further investigate the setup in my .htaccess.
Update #2
Using the .htaccess script below allows to remove .html extensions, redirect pages to a specific page within a directory and basically a working 404 not found page within a specific sub directory on a Hostgator cPanel grid hosting (apache).
Options -Indexes -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule !.*\.html$ %{REQUEST_FILENAME}.html [L]
RewriteRule ^arbeiten/$ /staging/arbeiten/alle [R=301,L]
RewriteRule ^journal/$ /staging/journal/journal-alle [R=301,L]
ErrorDocument 404 http://www.example.com/staging/404
Remaining 404 problem:
http://example.com/staging/blabla (404 works)
http://example.com/staging/folder/blala (404 works)
http://example.com/staging/folder/project-detail-pagexxx (404 works)
http://example.com/staging/folder/project-detail-pagexxx/ (404 does not work)

how to redirect to a 403 errors page

U have many 404 URLs in cgi-bin/ folder from 1 year ago;
But I don't redirect this page, because I'm using the following configuration:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ _main.php?url=$1 [L]
How can I get permission for control cgi-bin/* files ?
Try adding this before the RewriteEngine On line:
RewriteFule ^cgi-bin/ / [L,R=301]
This will redirect any request for the cgi-bin folder to your homepage (/).
after very tests ...
i used this code and worked ^_^(i linked to my mvc "_main.php" and redirected with my mvc setting)
ErrorDocument 403 /_main.php
ErrorDocument 404 /_main.php

.htaccess infinite loop on 404 in subfolders

I got a little problem concerning a project I'm working on.
I want to maintain only one .htaccess file in the root folder of this project. It is modular, so there are many different subfolders. My current .htacccess looks as follows:
ErrorDocument 401 /401.php
ErrorDocument 404 /404.php
RewriteEngine On
#strip www from domain
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
#ignore existing files and directories
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteRule .* - [L]
# Check if query string exists
RewriteCond %{QUERY_STRING} ^$
# Check that the request is not for an existing file
RewriteCond %{REQUEST_FILENAME} !-f
The problem is that every 404 error in a subfolder leads to an infinite loop because it looks for i.e. http://mydomain.tld/modules/index.php?p=404 instead of http://mydomain.tld/index.php?p=404 .
I know I could hardcode the URL in my .htaccess, but the problem is that it's kind of a community-hosting platform, where the community is specified dynamically via the subdomain and I want to keep the request in that specific subdomain.
Is there any possible way to force the .htaccess to use the index.php in the root-folder without giving the absolute url?
Thanks in advance!

.htaccess redirect to sub folder works occassionally

I have a site which runs from a sub directory - hosted on HostGator. Most of the htaccess rules work to redirect to the sub directory except for one.
if i go to example.com/products - I get an invisible redirect to example.com/subfolder/products - it appears correctly in the address bar as example.com/products
however if i go to example.com/news - I get a visible redirect to example.com/subfolder/news - it appears in the address bar incorrectly as example.com/subfolder/news
The following is the .htaccess code I am using in my root folder:
RewriteEngine on
RewriteRule ^$ /subfolder/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subfolder/$1 [L]
For reference: If I type example.com/news into the browser I am visibly redirected to example.com/subfolder/news - however if I type example.com/news into the browser a second time I am invisibly redirected!
Google has crawled the site and is serving the visible redirect urls (so they appear in Google as example.com/subfolder/news)
UPDATE:
In that .htaccess file the only other line I have it Options -Indexes
In the subfolder .htaccess file I also have
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L,QSA]
ErrorDocument 403 http://www.example.com/403
ErrorDocument 404 http://www.example.com/404
ErrorDocument 500 http://www.example.com/500
I'm with HostGator if that would have any bearing?

Resources