skip to Main Content

I tried to redirect but not working even I put the correct code from take it from web.

Redirect /index.php?page=8 /?page=8

2

Answers


  1. Your htaccess code should be.

    RewriteEngine On
    RewriteRule ^index.php?page=$1 /?page=$1 [R=301,NC,L]
    
    Login or Signup to reply.
  2. Redirect /index.php?page=8 /?page=8
    

    The mod_alias Redirect directive does not match against the query string, so the above directive will never match, so does nothing.

    To remove the index.php (directory index) from the visible URL, you would need to use mod_rewrite at the top of your .htaccess file. For example:

    RewriteEngine On
    
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^index.php$ / [R=301,L]
    

    The above will redirect a URL of the form /index.php?page=8 to /?page=8. Any query string present on the initial request is simply passed through to the target/substitution unaltered.

    The condition that checks against the REDIRECT_STATUS env var ensures we don’t get a redirect loop caused by mod_dir (or the Laravel front-controller) rewriting the request to index.php.

    Clear your browser cache and test first with a 302 (temporary) redirect.


    However, if you did only want to redirect the specific URL /index.php?page=8 (as stated in the question) to /?page=8 then you should write the rule like the following instead:

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,7}s/index.php?page=8sHTTP
    RewriteRule ^index.php$ / [R=301,L]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search