How do I internally redirect a request to a particular page using .htaccess without changing the URL bar.
Example: I want to redirect all 404 error to handle_controller.php.
I did the following:
RewriteCond %{REQUEST_FILENAME} !-d [NC
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule (.*) handle_controller.php?p=$1 [NC, R]
It's redirecting but it keeps updating the URL bar. For instance:
I request for invalid.php it redirects to handle_controller.php?p=invalid.php
How do I make it redirect internally to handle_controller.php while keeping the URL bar at invalid.php
I have used R=301 and R=302 but it isn't working.
Use:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) handle_controller.php?p=$1 [L]
[NC]
Is not useful when there is no text for comparison.
With [R]
it's a redirection, without only a rewrite.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.