FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

url rewrite

 


kv
I want to redirect

Quote:

http://something.com => http://en.something.com
http://www.something.com => http://en.something.com


but rest of the urls (like jp.something.com) should not be redirected.

How can I achieve this using mod rewrite? Or is there any other easy way of redirecting?
MrBlueSky
Put this in your .htaccess in the directory for which the rewrite must be done (or at the appropriate place in httpd.conf):

Code:

RewriteEngine On
^something.com(.*)$ en.something.com$1
^www.something.com(.*)$ en.something.com$1


it will rewrite (for example) http://something.com/print.php?page=3 to http://en.something.com/print.php?page=3.
qscomputing
I don't think that's what he's asking: by the looks of things, he wants redirection, not rewriting.
MrBlueSky
qscomputing wrote:
I don't think that's what he's asking: by the looks of things, he wants redirection, not rewriting.


Maybe. He indeed talks about redirecting, but also about mod_rewrite Smile

We'll see Wink
kv
I am not sure whether to use redirection (header(Location:)) or to use apache rewrite. I think mod rewrite is a bit complex and I have very less experience with it. But the problem with redirection is that I should be able to pass GET/POST variables also to the target along with the redirection.

Update: I tried

Code:
RewriteEngine On
^something.com(.*)$ en.something.com$1
^www.something.com(.*)$ en.something.com$1


but it didn't work. I got error "The server encountered an internal error or misconfiguration and was unable to complete your request."
MrBlueSky
Did you put it in .htaccess?
kv
Yes. I did. I am testing it on my linux box and not on frihost. I am not sure if rewrite is enabled. How can check if it is enabled? If it is enabled, then what else could be the problem?
Hogwarts
kv wrote:
Yes. I did. I am testing it on my linux box and not on frihost. I am not sure if rewrite is enabled. How can check if it is enabled? If it is enabled, then what else could be the problem?

Put this in index.html for the page you want redirected.
Code:
<meta http-equiv="refresh" content="0;url=http://127.0.0.1/en/">

or wherever you want it redirected to. Put this in the <head> tags, by the way.
kv
Hogwarts: From my previous post:

Quote:

But the problem with redirection is that I should be able to pass GET/POST variables also to the target along with the redirection.
Dosky
I advise to use a redirect in PHP, this way

Code:
 
<? 
header ("Location: url"); 
?> 


I hope you help yourself.. ^^
MrBlueSky
kv wrote:
Yes. I did. I am testing it on my linux box and not on frihost. I am not sure if rewrite is enabled. How can check if it is enabled? If it is enabled, then what else could be the problem?


Check if something like this

Code:

LoadModule rewrite_module modules/mod_rewrite.so


is in your httpd.conf file.

If it isn't run

Code:

./httpd -l


which list all the modules that are compiled into apache. If mod_rewrite also isn't there your server doesn't support rewrites
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.