Reputation: 56
Suppose i have a link generated in php:
http://localhost/Example/www.someDomain.com
now i would like to go to www.someDomain.com , can you please help me with the proper method (probably via .htaccess) to redirect to desired location.
I tried using php header function and js window.location.replace(" ") but it dint' helped.
***Problem with window.location.replace("www.someDomain.com")
is that instead of redirectng to www.someDomain.com , the page redirects to http://localhost/www.someDomain.com
I am using Wamp server if it helps. Help please and also suggest some nice resource to study about .htaccess Thanks
Upvotes: 0
Views: 1630
Reputation: 143846
htaccess is NOT going to help you at all. If all your links look like: http://localhost/...
then in order for htaccess to redirect, everyone who goes to your site would have to be running a webserver on their local machine and have an htaccess file that redirects to your site.
You need to fix your php scripts so they generate the correct hostname. Using javascript to redirect isn't even a viable solution, because in order for the location to be "localhost", they're already loading no content because they're trying to connect to their own machine.
If for whatever crazy reason you can't fix your scripts, you may have to look into using mod_proxy_html on your site and dynamically change all your "localhost" to your domain.
Upvotes: 0
Reputation: 329
If I understood.
you need to put te entire URL with "http://".
Javascript:
<script>
window.location.href=("URL");
</script>
OR in php:
<?php
header("location:$redirect");
?>
Upvotes: 1
Reputation: 1295
You can use window.location
or PHP header()
function, but for redirect to another site must prefix with http://
.
header("Location: http://www.example.com");
You can also do the same through Apache .htaccess
with a Redirect rule.
Upvotes: 0