Hi, We are redoing our website and we have removed / renamed a few old pages. I was wondering if I can do 301 redirect for removed / renamed pages without having to actually create them? To explain with an example: On old website : www.domain.com/mypage.php On new website: www.domain.com/mynewpage.php I created a 301 redirect in .htaccess redirecting mypage.php to www.domain.com/mynewpage.php without physically creating "mypage.php" file. When I access "www.domain.com/mypage.php", I get a 404 page not found error. When I create a blank "mypage.php", the redirection works fine. Is it possible to do a 301-redirect without having to create old files ? Thank you for the support. Best regards, Sans
yes, it is. you can use something like this in your .htaccess: RewriteEngine on RewriteRule ^mypage.php$ http://www.domain.com/mynewpage.php? [R=301,L] Code (markup):
Thx @RoseHosting yes it worked. Not sure why it did not work when I tried something similar previously. Do I need the trailing question mark after "mynewpage.php" ?? Thou redirection worked with and without the '?', but wanted to understand the syntax. Thx again
hi, the question mark is there to prevent a query string to be transferred to the new url. for example, if someone access www.domain.com/mypage.php?name=foo it will be redirected to mynewpage.php without the query string of '?name=foo'. I assumed you did not use query strings in your old url. If you are, then remove the question mark so the query strings are passed over to the new url you are welcome