Forum Moderators: phranque

Message Too Old, No Replies

Redirects to new directories

with htaccess or cpanel

         

Harry

3:29 pm on Jun 19, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello. I'm ending an mobile app-only version of my site and want to redirect viewers to the same version of the url in the mobile directory. There are thousands of pages/URLs.

Here is my configuration so far.

http://example.com/app/*article_app.html

to

http://example.com/mobile/*article_mobile.html

All articles in both folders have the same structure. I want to replicate this automatically for all articles/URLs without having to do it manually. I don't want to add a script to the defunct app pages.

I tried with mod redirects and to play with wild cards but I'm not achieving the right result. Is there a way to create one redirect for .htaccess on a Linux/CPanel server? I know this is very easy to many of you but I'm not longer a real geek!

Thank You



[edited by: not2easy at 7:52 pm (utc) on Jun 19, 2018]
[edit reason] readability [/edit]

lucy24

5:41 pm on Jun 19, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I tried with mod redirects
What does this mean? You said htaccess so presumably you’re on an apache server. What, exactly, did you try?

It is possible this question would be better served in the apache subforum. But before you consult an administrator, look up the rules governing "example.com". (Yes, you can say "example.mobi" or "example.xyz" if it is useful.)

phranque

9:21 pm on Jun 19, 2018 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



why not continue using the legacy urls?

Harry

12:44 pm on Jun 20, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The apps for the various platforms were released in 2010. Most of them crash and no longer work on new devices. Also, no one has accessed any of these pages in years. They are the exact same pages except for the _app tag.

phranque

1:39 pm on Jun 20, 2018 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



there's no reason the "*-mobile" versions of these pages couldn't use the same directory and file names as the "*-app" versions.

do you have an articulable reason, technical or otherwise, for using different urls for essentially the same content?

lucy24

4:19 pm on Jun 20, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



there's no reason the "*-mobile" versions of these pages couldn't use the same directory and file names as the "*-app" versions
I thought it meant that the two versions, -mobile and -app, have existed in parallel from the beginning, and now he needs to collapse them all into one set of URLs.

Still waiting for an answer to the “What have you tried so far?” question, though. If it’s a simple replace--change "app" to "mobile" (or was it the other way around?) while keeping everything else the same--it should be straightforward, so there must be something we’re missing.

phranque

10:29 pm on Jun 20, 2018 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I thought it meant that the two versions, -mobile and -app, have existed in parallel from the beginning, and now he needs to collapse them all into one set of URLs.

the title says "new" directories.

lucy24

11:26 pm on Jun 20, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Heh. I took it to mean “different”, in the same way that “our store has moved to a new location” doesn’t necessarily mean it’s a brand-new building.

Gosh. We could just happily speculate all day about what OP really meant, but there’s only one person who knows for sure :)

phranque

11:37 pm on Jun 20, 2018 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



“our store has moved to a new location” doesn’t necessarily mean "we are closing our old location and moving the store to our other branch"

lucy24

3:54 am on Jun 21, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I was just referring to interpretations of the word “new”. But if we are continuing the redirect analogy, then “our store has moved” means “we’re not even going to tell you whether the old location is still standing, and there is no way for you to find out, because you’re not going to be allowed to go there; it’s our new location or nothing”.

Poor Harry. You’re more confused than you were at the outset, aren’t you?

tangor

4:05 am on Jun 21, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sounds like an attempt to make poor/lost traffic pages resurrect magically with a redirect. Ain't gonna work in that regard. g, after all, never forgets a url it has met ... and in that regard indicates the material is page 3007... or more.

Unless I'm missing something else!

Harry

6:47 am on Jun 21, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello. I don't want to "justify" any further why I want to collapse the app pages. I don't have to justify my decision to anyone but myself. I'm not here to discus business strategy. I'm asking a technical question. I just need a solution to create a redirect from the app pages to the mobile version.

I'm not sure what is so unclear or confusing.

Thank you.

phranque

7:17 am on Jun 21, 2018 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



what is confusing is understanding both your technical requirements and your business strategy.
i would be willing to leave it at helping you with your technical requirements but you have to answer the technical questions that have been asked first.

Harry

1:42 pm on Jun 21, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unsure about what is unclear technically and that has not been answered already. I did a mod redirect but I can't do one that covers each page automatically without sending them into a generic url.

I want article123_app.html to redirect to article123_mobile.html
I want article456_app.html to redirect to article456_mobile.html
I want article789_app.html to redirect to article789_mobile.html

I don't want to do this manually nor put a script in the _app pages as I want to get rid of them. There are over 15k pages to redirect from app to another 15k pages in mobile.

phranque

2:08 pm on Jun 21, 2018 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Unsure about what is unclear technically and that has not been answered already. I did a mod redirect but...

What, exactly, did you try?

Harry

2:37 pm on Jun 21, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteRule ^app$ "http\:\/\/example\.com\/mobile" [R=301,L]

phranque

3:05 pm on Jun 21, 2018 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



since your specified Pattern has anchors at both ends you need to change this so it matches the entire url path.
you don't need those backslashes or quotes in the Substitution string.
you should use capture groups in the Pattern that match the variable part of the url and use backreferences to insert those captured strings into the substitution string.

https//httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
http://perldoc.perl.org/perlre.html#Capture-groups

Harry

3:32 pm on Jun 21, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm sorry but I am not a developer/coder. Can you please explain your example for a dummy? I don't know how to use the example that you provided.
Thank you.

Harry

3:38 pm on Jun 21, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you saying that I should use this form?

example.com/app/_app.html#rewriterule
example.com/mobile/_mobile.html#Capture-groups

lucy24

4:04 pm on Jun 21, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



phranque is pointing to a couple of pages in the mod_rewrite docs. You have to copy-and-paste into your browser's address bar, because the Forums software will otherwise eat fragment links.

No, you cannot use fragments in the pattern of a RewriteRule. (You can in a target, with the appropriate flag, but fortunately it doesn't apply.)

Way back in the initial post it looked as if two things were getting changed: the directory and part of the filename:
http://example.com/app/*article_app.html
>>
http://example.com/mobile/*article_mobile.html
It's not entirely clear what you meant by the * asterisk here: did you mean that this is the variable part, as in
/app/foo_app.html
/app/bar_app.html
/app/hinky_app.html
/app/sketchy_app.html
and so on?

It is possible you’ve misunderstood the function of anchors. (This is pretty common.) They mean “the beginning (or end) of the entire string that you’re evaluating”, not just the beginning or end of the current rule’s pattern. An opening anchor would indeed be appropriate, because if the pattern begins
^app/
then if the current request happens to be for something other than the /app/ directory the server can immediately stop looking, and move on to the next rule. There’s no need for a closing anchor.

Harry

4:49 pm on Jun 21, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's not entirely clear what you meant by the * asterisk here: did you mean that this is the variable part, as in
/app/foo_app.html
/app/bar_app.html
/app/hinky_app.html
/app/sketchy_app.html
and so on?


Yes that is correct.

tangor

11:13 am on Jun 23, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What adjustments have you made? Any success?