简体   繁体   中英

redirect through .htaccess file

I have made one file say a.php. Now I want some thing like if one tries to open a.php then He should ne redirected to another page of same directory of site.

I want it throght .htaccess file. I have written this code in my .htaccess file

RewriteEngine On
# This allows you to redirect index.html to a specific subfolder
Redirect /b.php /a.php 

both pages are stored in same directory..

You could try

RewriteEngine On
RewriteRule /a\.php /otherfile.php [R=301,L]

Change the filenames were necessary. If you could be more specific as to what you wish to achieve,perhaps I can supply you with a better solution.

Question that might help:

  • Is it only for the file a.php, or there are other request that will be handled the same way as this pattern?

Hope it helps!

Please refere to the link below. I think so it will help you out.

How do I redirect my site using a .htaccess file?

Thanks

Or, you can use this if your script has a request string.
Like you want to stay on the same page, but not to show a request string.

(in case you want to post or get some data through scripts)

RewriteEngine on
RewriteRule ^/path/to/a/([0-9]+) /path/to/a.php?foot=$1 [PT]

Also, you should consult with the link Codemaster Gabriel and Arvind Sridharan gave you.

you can use header function in order to redirect.. try this

inside a.php type:-

    <?php
    header ('location: b.php'); //lets say b.php is the file you want to redirect
    ?>

it will work.. and it is recommended to use this instead of .htaccess due to security reason of apache

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM