Welcome to WebmasterWorld Guest from 54.158.248.112

Forum Moderators: Ocean10000 & phranque

Redirects to new directories

with htaccess or cpanel

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 27, 2003
posts: 730
votes: 2


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]

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

Senior Member from US 

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

joined:Apr 9, 2011
posts:14932
votes: 653


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.)
9:21 pm on June 19, 2018 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:11388
votes: 157


why not continue using the legacy urls?
12:44 pm on June 20, 2018 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 27, 2003
posts: 730
votes: 2


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.
1:39 pm on June 20, 2018 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:11388
votes: 157


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?
4:19 pm on June 20, 2018 (gmt 0)

Senior Member from US 

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

joined:Apr 9, 2011
posts:14932
votes: 653


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.
10:29 pm on June 20, 2018 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:11388
votes: 157


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.
11:26 pm on June 20, 2018 (gmt 0)

Senior Member from US 

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

joined:Apr 9, 2011
posts:14932
votes: 653


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 :)
11:37 pm on June 20, 2018 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:11388
votes: 157


“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"
3:54 am on June 21, 2018 (gmt 0)

Senior Member from US 

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

joined:Apr 9, 2011
posts:14932
votes: 653


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?
4:05 am on June 21, 2018 (gmt 0)

Senior Member from US 

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

joined:Nov 29, 2005
posts:8461
votes: 652


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!
6:47 am on June 21, 2018 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 27, 2003
posts: 730
votes: 2


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.
7:17 am on June 21, 2018 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:11388
votes: 157


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.
1:42 pm on June 21, 2018 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 27, 2003
posts: 730
votes: 2


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.
2:08 pm on June 21, 2018 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:11388
votes: 157


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

What, exactly, did you try?
2:37 pm on June 21, 2018 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 27, 2003
posts: 730
votes: 2


RewriteRule ^app$ "http\:\/\/example\.com\/mobile" [R=301,L]
3:05 pm on June 21, 2018 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:11388
votes: 157


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
3:32 pm on June 21, 2018 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 27, 2003
posts: 730
votes: 2


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.
3:38 pm on June 21, 2018 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 27, 2003
posts: 730
votes: 2


Are you saying that I should use this form?

example.com/app/_app.html#rewriterule
example.com/mobile/_mobile.html#Capture-groups
4:04 pm on June 21, 2018 (gmt 0)

Senior Member from US 

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

joined:Apr 9, 2011
posts:14932
votes: 653


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.
4:49 pm on June 21, 2018 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 27, 2003
posts: 730
votes: 2


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.
11:13 am on June 23, 2018 (gmt 0)

Senior Member from US 

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

joined:Nov 29, 2005
posts:8461
votes: 652


What adjustments have you made? Any success?