Answer the question
In order to leave comments, you need to log in
How to give a 404 error when adding extra characters, dots, etc.?
I ran into such a problem that when adding extra characters to the url address, a 404 error does not pop up. I use CNC and when adding extra characters to GET variables (mysite.ru/gorod/moskva ,qwe&asas ), punctuation marks, etc., no 404 error is issued. Here is what I have in htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !- d
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^(.+)/$ /$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^gorod/ ([^/]*)/(.*)$search.php?city=$1&value=$2 [L]
RewriteRule ^gorod/(.+)$ city.php?city=$1 [L]
RewriteRule ^login/(.+)$ login.php?value=$1 [L]
RewriteRule ^join/(.+)$ join.php ?value=$1 [L]
RewriteRule ^help/(.+)$ help.php?value=$1 [L]
RewriteCond %{THE_REQUEST} ^[AZ]{3,9}\ /index\.php\ HTTPS
RewriteRule ^ index\.php$ https://mysite.ru/ [R=301,L]
RewriteCond %{http_HOST} ^www.mysite\.ru$ [NC]
RewriteRule ^(.*)$ https://mysite.ru /$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L ]
RewriteCond %{REQUEST_URI} ^/index$ [OR]
RewriteCond %{REQUEST_URI} ^/index[.]+(\w+)$
RewriteRule . / [R=301,L]
AddDefaultCharset UTF-8
ErrorDocument 404 /errors.php
Is there a solution in htaccess or do I need to check if there is anything in mysqli_num_rows via php? if there is, then everything is OK, if not, then rewrite to 404? I would like in htaccess :)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question