0
votes

How to redirect url like "http://www.example.com/pathstring=something" to error page using htaccess file. "http://www.example.com/path" this is part of url and "string=something" is part of query string. if someone misses the "?" in query string, the page should redirect to error page.
Here is my htaccess code

 RewriteEngine on  
  RewriteCond %{REQUEST_FILENAME} !-f  
  RewriteCond %{REQUEST_FILENAME} !-d  
  RewriteRule ^(.*)$ index.php?/$1 [L,QSA]  
2
Can you share the htaccess code you have so far? so that we know how to help you better - Tayo.dev
hi paul, shared htaccess code as you suggested - Three-Eyed Raven

2 Answers

0
votes

You can use it:

RewriteRule ^path([A-Za-z0-9-]+)$ /error-page.html [R=301,L]

If there is no "?" after path, it'll redirect to error page

0
votes

Oh well, there is no way http://www.example.com/pathstring=something will redirect to a rewrite rule with: http://www.example.com/path?string=something.

However, if http://www.example.com/pathstring=something is not a valid URL and no rewrite rule of that path in your .htaccess, you can redirect to all not found pages to a 404 page. Add this to you .htaccess

RewriteEngine On 
ErrorDocument 404 /my-404-page.html