Why 404.html page is not shown - .htaccess

I have this .htaccess
RewriteEngine On
ErrorDocument 404 /404.html
RewriteBase /
RewriteRule ^$ index\.html
RewriteRule ^(.+)\.html$ index.php?page=$1 [L]
RewriteRule ^robots.txt$ /generator.php?what=robots [L]
RewriteRule ^sitemap.xml$ /generator.php?what=sitemap [L]
If I go at: site.com/blablalblabla
I get 404 NOT FOUND, but it doens't show my 404.html page. Why?
Thank you

IMHO if the server fires up a 404, the 404.html will be the new REQUEST_URI to transform. The new uri will also go over all the rewrite rules and ending up redirected to index.php?page=404.
Try do add this rule condition:
RewriteCond %{REQUEST_URI} !^\/404\.html$
RewriteRule ^(.+)\.html$ index.php?page=$1 [L]

Try making a 404.md file with the following inside:
---
permalink: <insert 404 file path here>
---

Related

.htaccess redirect with condition

here is my rules for htaccess file.
RewriteRule ^admin/?$ admin/index.php
RewriteRule ^cart/([0-9]+)/?$ cart.php?t=$1
RewriteRule ^register$ register.php
RewriteRule ^login$ login.php
RewriteRule ^forgot-password$ forgot_password.php
RewriteRule ^terms-and-conditions$ terms_and_conditions.php
RewriteRule ^request-consideration$ request_consideration.php
RewriteRule ^([a-z0-9\-]+)/?$ products.php?cid=$1
RewriteRule ^([a-z0-9\-]+)/([a-z0-9\-]+)/?$ products.php?cid=$1&scid=$2
RewriteRule ^([a-z0-9\-]+)/([a-z0-9\-]+)/([a-z0-9\-]+)/?$ product_details.php?cid=$1&scid=$2&id=$3
ErrorDocument 404 /error_404.php
Now the problem is when i try to redirect it say www.example.com/cart/123 it goes products.php page. I want to restrict the url www.example.com/cart/123 only. so www.example.com/cart or www.example.com/cart/abc will redirect to error_404 page. same for other also like register, login etc.
Any help would be appreciated. Thanks in advance.
Based on you comments, you want to redirect the uri to 404 page if /cart or /cart/abc is requested, you can use the following rules. Put this at the top of your htaccess before other RewriteRules
RewriteEngine on
RewriteRule ^cart/?$ - [R=404,L]
RewriteRule ^cart/[A-Za-z]+/?$ - [R=404,L]

404 page not working on website, help me to sort out Htaccess issue

I have removed this post from our database entirely but the below link is still showing blank template instead of 404 not found error,
http://www.myconsumercourt.com/complaints/online-shopping/men-clothing/complaint-against-livastar-backlift-technologies-pvt-ltd-1421.html
here is my .htaccess code
RewriteEngine on
ErrorDocument 404 /404.php
RewriteRule ^(.*)/$ /$1 [R,L]
RewriteRule ^complaints/(.*)/(.*)/(.*)-(.*).html$ post-info.php?ticket-number=$4 [L]
RewriteRule ^complaints/(.*)/(.*)$ query-listing.php?sub-category=$2 [L]
RewriteRule ^complaints/(.*)$ subject-list.php?category=$1 [L]
Please help me to redirect my broken page to 404.php page.
Thank you so much.
Kind Regards,
This is because your first RewriteRule is rewriting this url to an existent file.
put the following rule bellow "RewriteEngine on" line to redirect the url to 404.
RewriteCond %{THE_REQUEST} /complaints/online-shopping/men-clothing/complaint-against-livastar-backlift-technologies-pvt-ltd-1421\.html [NC]
RewriteRule ^ - [L,R=404]

htaccess - Redirect to joomla webpage

I know this is probably a very simple question but I do not manage it to get it working.
I have a joomla application with the following url: http://www.nmo-online.com/news/final and I would like to point it to http://www.nmo-online.com/client/frontend/app/final but with keeping the first url.
So I put a .htaccess file on my server situated in the root folder with the following content:
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} .*nmo-online.com$
RewriteRule ^news/final client/frontend/app/final [L]
The redirection seems to work but I always get redirected to the homepage, which is http://www.nmo-online.com/weather.
Any help is very appreciated.
enne
Edit: Here is the complete htaccess-file
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} .*nmo-online.com$
RewriteRule ^$ client/frontend/questionnaire/index.php [L]
RewriteRule ^weather client/frontend/app/weather [L]
RewriteRule ^news/final client/frontend/app/final [L]
RewriteRule ^flight/search-flight client/frontend/app/search-flight [L]
#Joomla backend
RewriteRule ^administrator client/frontend/app/administrator/ [L]
#Questionnaire backend
RewriteRule ^backend client/backend/index.php [L]

Url rewrite and trim url

I need your precious help.
I have an url:
http://domain.com/v/12345
My ht access is set to pass 12345 to php script like:
htaccess:
RewriteRule ^v/([a-zA-Z0-9_-]+)$ /script.php?v=$1 [L]
script php:
http://domain.com/script.php?code=12345
and works perfectly but.. and there is a but, I would write my url so:
http://domain.com/12345/my-dog-is-very-fat
can you help to change my htaccess to works so? Because if I use /my-dog-is-fat or just / I get an 404 error.
I try to explain better:
I would share link with seo keywords in the url, example
mydomain.com/alphanumericCode/thi-is-my-dog-article
where alphanumericCode is get of myscript.php?V=
This is my htaccess:
RewriteEngine On
RewriteRule ^view/([a-zA-Z0-9_-]+)$ /view.php?v=$1
RewriteRule ^folder/([a-zA-Z0-9_-]+)$ /filefolderlist.php?f=$1
RewriteRule ^home$ /index.php [L]
RewriteRule ^report$ /report.php [L]
RewriteRule ^play/([a-zA-Z0-9_-]+)$ /play.php?v=$1 [L]
###Added by anubhava
RewriteRule ^v/([\w-]+)/?$ /script.php?v=$1 [L,QSA]
RewriteRule ^([0-9a-z]+)/.+$ /script.php?v=$1 [L,QSA,NC]
##end
RewriteRule ^privacy-policy$ /privacy.php [L]
ErrorDocument 404 404.php
You can have a new rule for the new URI scheme:
RewriteEngine On
RewriteRule ^v/([\w-]+)/?$ /script.php?v=$1 [L,QSA]
RewriteRule ^([0-9a-z]+)/.+$ /script.php?v=$1 [L,QSA,NC]

.htaccess causing redirect loop

I have a URL on my site that works without a / but when I add a / it says there's a redirect loop... I'm struggling to see the problem here....
Options -indexes
RewriteEngine On
#
#
#php_value output_handler ob_gzhandler
php_value output_handler none
php_flag register_globals off
php_flag safe_mode off
ErrorDocument 404 /404
#
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]
#
RewriteCond %{HTTP_HOST} !^www.domain.com$
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]
RewriteRule ^battery/([^/]+)$ /browser/product?sku=BATTERY+$1&type=battery
RewriteRule ^vehicles/([^/]+)/([^/]+)/([^/]+)/product([0-9]+)$ /browser/index.php?make=$1&model=$2&id=$3&%{QUERY_STRING} [L,NC]
RewriteRule ^vehicles/([^/]+)/([^/]+)/([^/]+)/([0-9]+)$ /browser/product.php?make=$1&model=$2&year=$3&id=$4&%{QUERY_STRING} [L,NC]
RewriteRule ^vehicles/([^/]+)/([^/]+)/([^/]+)$ /store/product/list.php?make=$1&model=$2&year=$3&%{QUERY_STRING} [L,NC]
RewriteRule ^vehicles/([^/]+)/([^/]+)$ /vehicle/make/model/year/list.php?make=$1&model=$2&%{QUERY_STRING} [L,NC]
RewriteRule ^vehicles/([^/]+)$ /vehicle/make/model/list.php?make=$1&%{QUERY_STRING} [L,NC]
RewriteRule ^vehicles/$ /vehicle/make/list.php{QUERY_STRING} [L,NC]
RewriteRule ^keyfinder /browser/product?id=1001552 [L,NC]
I probably would have done some of the regular expression different for the RewriteRule, but it seems to be working accept for that trailing slash. Add /? to the end of each one of your RewriteRules for vehicles, battery & keyfinder. The /? is saying to look for zero or one trailing slash at the end of the line.
Here is an example:
RewriteRule ^vehicles/([^/]+)/([^/]+)/?$ /vehicle/make/model/year/list.php?make=$1&model=$2&%{QUERY_STRING} [L,NC]
RewriteRule ^vehicles/([^/]+/?)$ /vehicle/make/model/list.php?make=$1&%{QUERY_STRING} [L,NC]
RewriteRule ^vehicles/?$ /vehicle/make/list.php{QUERY_STRING} [L,NC]
The changes above will solve the problem of the redirecting loop caused by the trailing slash, but not the redirecting loop itself. You might have expected your 404 page to show up instead. It didn't work because "ErrorDocument" is wrong. There is no extension for the 404 page.
So again as an example, if your error page is called 404.php, the line needs to look like this...
ErrorDocument 404 /404.php
Hope this helps
Is it possible to have the log of the rewrite engine ?
Add the following lines in your configuration (bellow the RewriteEngine On is enough) :
RewriteLog logs/rewrite_https.log
RewriteLogLevel 15
I suppose your others logs are in logs/

Resources