简体   繁体   中英

How to redirect static URL

I am having a php html site hosted on server. I've url like http://www.test.com/sales.php when user click on the link of this url then it should show www.test.com/services/sales.php instead of www.test.com/sales.php .

I've tried following code but it is not working.

RewriteEngine On

RewriteRule ^http://www.test.com/services/sales.php$ http://www.test.com/sales.php [R=301,NE,NC,L]

You can use like that

htaccess:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^sales/? http://www.test.com/services/sales.php [R=301,L]

This is the more robust version that can also be used in the real http server configuration:

RewriteEngine On
RewriteRule ^/?sales\.php$ /services/sales.php [R=301]
RewriteRule ^/?services/sales\.php$ /sales.php [END]

If you want to have a clean URL (" https://example.com/services/sales " instead of " https://example.com/services/sales.php "), then this variant would make sense:

RewriteEngine On
RewriteRule ^/?sales\.php?$ /services/sales [R=301]
RewriteRule ^/?sales/?$ /services/sales [R=301]
RewriteRule ^/?services/sales/?$ /sales.php [END]

It is a good idea to start with a 302-redirection and only change that to a 301 once everything is working as expected. When using a 301 right away you might run into issues with caching, so you should always use a fresh anonymous browser tab when testing.

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