Welcome to WebmasterWorld Guest from 54.145.209.34

Forum Moderators: Ocean10000 & incrediBILL & phranque

Cannot 301 redirect this page to a specific page

   
1:58 am on Jul 23, 2013 (gmt 0)



I want this page:

http://mystore.com/Login.aspx?ReturnUrl=%2fPages%2fHome%2fUser%2fWish-list.aspx


to

http://mystore.com/en/ukeurope/home


So, I try to write a 301 redirection rule like this:

RewriteRule ^Login.aspx$ en/ukeurope/home? [R=301,L]


but when I want to try this redirection.
It gives me 404 not Found.

P.S. I don't want another one that is

mystore.com/Page/Login.aspx


to be redirected by this 301 redirection rule
2:49 am on Jul 23, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



Ouch, ouch. Where to start?

but when I want to try this redirection.
It gives me 404 not Found.

Where do you get the 404? At the originally requested URL (Login.aspx), at the new one, or somewhere else? If you are trying it in a browser, the address bar will say where the browser "thinks" it is.

I don't want another one that is

mystore.com/Page/Login.aspx

to be redirected by this 301 redirection rule

You have correctly handled this by using an opening anchor in your pattern. Can I assume this is happening in htaccess? If so, you are also correct to leave off the opening directory slash in the pattern.

Is this rule preceded by
RewriteEngine On
? Unlike most things in Apache, mod_rewrite activity isn't inherited. You need to turn it on afresh in each htaccess. (Twice, if you've got RewriteRules inside Files or FilesMatch envelopes. But you're not really supposed to do this anyway.)

You should also have
Options +FollowSymLinks
but this has almost certainly been turned on by your host already so it's not likely to be an issue if you forget it.

to

http://example.com/en/ukeurope/home

And then what? It is technically possible to have a file on your server named just "home" with no extension yes, Phranque, I'm listening but in practice you'd never do it. So there would have to be a follow-up internal rewrite that takes the new URL and points to wherever its content "really" lives. It might even be "Login.aspx".

en/ukeurope/home? [R=301,L]

Ouch more. That is the worst possible form of a target. Include the full protocol and hostname. At an absolute minimum, start with a / directory slash. Assorted bad things can happen if you don't. At best, the server will use whatever you've set as your RewriteBase. (By default it would be the / document root.)

None of this answers the real puzzler:

original request
http://example.com/Login.aspx?ReturnUrl=%2fPages%2fHome%2fUser%2fWish-list.aspx

desired redirect
http://example.com/en/ukeurope/home

What happens the query string? You've explicitly removed it from the target by putting a ? at the end. But there's nothing in the rule that would constrain redirects to only requests with this particular query-- or any query at all. Do you want to constrain the rule, or did you just put in the query as an example?

[edited by: bill at 6:59 am (utc) on Jul 23, 2013]
[edit reason] fixed typo [/edit]

3:36 am on Jul 23, 2013 (gmt 0)



To lucy24
In the site's htaccess file, There are many redirection rules that are work except the rule in the topic.

I try your suggestion but it's not work.

I try to write the rule like this:
RewriteRule (.*)Login.aspx$ en/ukeurope/home? [R=301,L]

but this rule affect to this url too which I don't want:
mystore.com/Page/Login.aspx

and I look in the address bar of web browser. It's still :
mystore.com/Login.aspx?ReturnUrl=%2fPages%2fHome%2fUser%2fWish-list.aspx

but the page show 404 not found
4:02 am on Jul 23, 2013 (gmt 0)

WebmasterWorld Senior Member Top Contributors Of The Month



The left side of your rule was fine initially, except for the unescaped . (dot) -- (It should be: ^Login\.aspx$). The right side is still incorrect -- (The right side should be an absolute URL for a redirect, meaning it should start with http:). If you need to match the exact query_string (stuff after the ?) you're posting you'll need to use a condition.

There are some tutorials at the bottom of the page in the Library [webmasterworld.com] that should help you understand more about rewriting and redirecting.
4:54 am on Jul 23, 2013 (gmt 0)



Finally, I found the correct one:
RewriteRule ^/Login\.aspx$ en/ukeurope/page/home? [R=301,L]
5:09 am on Jul 23, 2013 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, thsecmaniac!


if this rule is in the .htaccess file then it shouldn't match a leading slash in the Pattern.
the Substitution string should begin with the protocol and hostname.
more like this:
RewriteRule ^Login\.aspx$ http://example.com/en/ukeurope/page/home? [R=301,L]
6:06 am on Jul 23, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



I try your suggestion but it's not work.

Uh-oh. I don't think I actually made a specific suggestion did I? I didn't get past pointing up some problems.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month