Such a question: for example, some wise guy wants to enter the path to the file (for example, not sie/category , but site/views/category/index.php ), can I recognize this and redirect it to the main page ( site/ ) ?
2 answers
in root .htaccess
RewriteEngine on RewriteRule '^site/views/(.*)(.php)$' /site [R=302,L] - with this server error option, I want to redirect if it is possible - Tofiq Şamedov
- @ TofiqŞamedov corrected the answer - tcpack4
The question immediately arises: why? What are you trying to hide? Is it somehow related to SEO (want to avoid duplicates ...)?
Everything can be done.
Through the engine itself (self-written and / or framework).
Through the web server. In your case, as I understand it Apache: via .htaccess
What is better in your case, I do not know, because I do not know:
- What is your engine and how it is configured routes.
- What do these routes look like?
If through .htaccess, look away:
- URL Rewriting Guide
- Apache Module mod_rewrite
- 301 redirect (redirect) via .htaccess (the first thing that came across )
It will be necessary to prescribe for each group of the route.
If through the site's engine (PHP scripts), you need to know how these routes are organized and through what are configured.
To you, as I understand it, it is important that the page (URL) entered by the user is redirected to the corresponding page (URL)? And only if such a page does not exist - the web server should return 404 code.