Answer the question
In order to leave comments, you need to log in
How to redirect all links that do not contain a certain string through htaccess?
In particular, a valid link pattern mydomain.com/mypage.php?j=random string
good link examples
mydomain.com/mypage.php?j=sdhfv289gf234f834
mydomain.com/mypage.php?j=ascf2i9bf34f34f
mydomain.com/mypage.php? j=ws0cq0wjd023d34f
All other links should be redirected to one other page, for example mydomain.com/bad.php
Answer the question
In order to leave comments, you need to log in
You can probably do better, but it seems to work:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/bad\.php
RewriteCond %{REQUEST_URI} !^/mypage\.php [OR]
RewriteCond %{QUERY_STRING} !^j=[^&]+$
RewriteRule .* /bad.php? [R=301,L]
and what does the wrong link look like, can you give an example?
For a correct link, there must be some rule, for example, the first 3 characters of a letter, then 1 number, 3 more letters and a number, otherwise it will be impossible to determine incorrect links
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question