homepage Welcome to WebmasterWorld Guest from 54.167.173.250
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
help me to redirect a directory to url
redirect a url
ygalbrami




msg:4611563
 9:52 am on Sep 21, 2013 (gmt 0)

hello i am very very new to write a code in .htaccess
i search over the net for a code for me, and i have try to write a code myself with no luck, so i really need help on this.

i have the url: mysite.com/login/
need to redirect to mysite.com/index.php?rt=account/login

how can it's be done?
please help.

 

g1smd




msg:4611565
 9:57 am on Sep 21, 2013 (gmt 0)

Why would you want to redirect from a friendly URL to one with parameters?

Perhaps you want a rewrite? This is where the user requests /login/ and behind the scenes /index.php?rt=account/login is processed without revealing that is what is going on.

ygalbrami




msg:4611566
 10:07 am on Sep 21, 2013 (gmt 0)

i want to rewrite the url
login/ directory don't really exist - i now this is a friendly url
that's why i need to redirect it.

i want to create a login button with this url login/
to go to the original link mysite.com/index.php?rt=account/login

i don't know to make the code, if you know please help me.

lucy24




msg:4611632
 8:10 pm on Sep 21, 2013 (gmt 0)

i want to rewrite the url
login/ directory don't really exist - i now this is a friendly url
that's why i need to redirect it.

No, you don't. You want to rewrite it. That means the user continues to see the nice friendly URL, but your server secretly provides content from index.php?something=something-else

There are by this time several hundred posts explaining how to capture part of a request and do a rewrite. The one important thing your first post doesn't make clear is: How many different pages are involved? And how many different patterns within that URL?

Has your long ugly URL ever existed? That is, been used publicly? If yes, you will also need to make a rule redirecting (not rewriting) from the old ugly URL to the new pretty one. If the ugly one has never been publicly visible, you may be able to ignore this part.*

The patterns are:

RewriteCond %{THE_REQUEST} part-of-ugly-URL-here
RewriteRule ugly-url http://www.example.com/pretty-url [R=301,L]

RewriteRule pretty-url /ugly-url [L]


* I stress "you may". My newest test site recently got hit with a slew of explicit requests for "forbidden.html" (generic 403 page). I can't figure out what I did wrong, but for safety's sake I coded a 410 for any passing robot that asks for it by name.

ygalbrami




msg:4611639
 8:48 pm on Sep 21, 2013 (gmt 0)

the long url really exist and he have 1 page only.
i have about 5 ugly url need to change to pretty url
and yes you are correct i need my server will show the content of ugly url but show to users pretty url,

i have not posted the ugly url yet.
i very need your help
i try your code and it does nothing when i go to mysite.com/login
i see page not found.

this the code


RewriteCond %{THE_REQUEST} http://www.mysite.com/index.php?rt=account/login
RewriteRule http://www.mysite.com/index.php?rt=account/login http://www.mysite.com.com/login [R=301,L]

RewriteRule http://www.mysite.com.com/login /http://www.mysite.com/index.php?rt=account/login [L]


what i do wrong?
thank you so much for trying to help me

[edited by: phranque at 9:03 pm (utc) on Sep 21, 2013]
[edit reason] unlinked urls [/edit]

lucy24




msg:4611656
 10:29 pm on Sep 21, 2013 (gmt 0)

RewriteRule http:/ /www.mysite.com.com/login /http://www.mysite.com/index.php?rt=account/login

Spend a little time reading earlier posts in this forum. Also look at the Forums Charter where it explains about using "example.com". This is a general rule in WebmasterWorld forums, but it is doubly important in /apache/ because we need to see exactly what you typed. (This time a moderator came along and tweaked your post to get rid of auto-linking. But you can't rely on this.) It can be example.org or example.anything if you need to name more than one domain, but it has to be the exact word "example".

There are two fatal mistakes in your rule as posted. They won't crash the server, but mistake #1 will prevent the rule from working-- ever-- and mistake #2 will prevent it from working as intended.

#1 A RewriteRule sees only the "path" part of a request. In htaccess (or in a <Directory> section in the config file) it begins with a directory name, no leading / slash. DO NOT include your domain name. DO NOT include the query string.

If your rule needs to look at the hostname and/or the query, that has to go in a RewriteCond.

#2 The target of a rewrite (flag in [L] alone, no [R]) must begin with a / slash representing the root. If you include the protocol-and-domain it will turn into a redirect whether you want it to or not. I don't know what happens if you start with /http, but it is always a mistake.

JD_Toims




msg:4611657
 10:40 pm on Sep 21, 2013 (gmt 0)

RewriteCond %{THE_REQUEST} http://www.mysite.com/index.php?rt=account/login
RewriteRule http://www.mysite.com/index.php?rt=account/login http://www.mysite.com.com/login [R=301,L]

RewriteRule http://www.mysite.com.com/login /http://www.mysite.com/index.php?rt=account/login [L]

The RewriteRule will not see the protocol [http://], the host [www.example.com], or the query_string [the ? and anything after it] so you'll need to do a couple things different -- Please note the edits below.

RewriteCond %{THE_REQUEST} [A-Z]{3-9}\ /index\.php\?rt=account/login\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/login [R=301,L]

RewriteRule ^login$ /index.php?rt=account/login [L]

ygalbrami




msg:4611659
 11:02 pm on Sep 21, 2013 (gmt 0)

yea this work, so cool
thank you so much for all the help - this code also not work for me so i have put the code on top of all codes and it works.

thank you so much for everyone of you.

JD_Toims




msg:4611661
 11:12 pm on Sep 21, 2013 (gmt 0)

Glad we could help you get it figured out, and by-the-way: Welcome to WebmasterWorld!

ygalbrami




msg:4611663
 11:23 pm on Sep 21, 2013 (gmt 0)

thank you so much...
happy to be here and learn new stuff

g1smd




msg:4611749
 8:09 am on Sep 22, 2013 (gmt 0)

One thing that is very important, is the order of the rules.

If you have other rules in your htaccess file, putting rules in the wrong order can stop things working completely, if you're lucky, or stop them working correctly, but in a way that you don't immediately notice, if you're unlucky.

ygalbrami




msg:4611769
 10:30 am on Sep 22, 2013 (gmt 0)

now i know that the order is important, that why i have tested a lot's of code and nothing works.
just 1 last thing, i have try to redirect this link (home page link)
http://www.example.com/index.php?rt=index/home
to this home page http://www.example.com

i have try this code:
RewriteRule ^$ /index.php?rt=index/home [L]
but nothing happend

any idia?

thank you so much

[edited by: phranque at 10:52 pm (utc) on Sep 22, 2013]
[edit reason] exemplified domain [/edit]

lucy24




msg:4611776
 12:15 pm on Sep 22, 2013 (gmt 0)

When you say redirect do you mean rewrite? The code you've quoted takes a request for the domain root and serves content from index.php et cetera. This would seem to be exactly what you want to do.

Now, I'm developing a nasty suspicion that you've got the "redirect" and "rewrite" concept precisely backward.

The pattern-- the part on the left-- is what the visitor originally asked for. The target --the part on the right-- is where you send them. It can either be an explicit redirect ([R=301] flag, browser's address bar changes) or a behind-the-scenes rewrite ([L] flag, user doesn't know you've done anything).

If you want to grab requests for
index.php et cetera
and send them to a bare
/
(browser's address bar says only www.example.com/) you need to turn the rule in the other direction. The target should include the full http:/ blahblah, and there has to be a [R=301,L] flag.

See above about using example.com. There's a reason for the rule.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved