homepage Welcome to WebmasterWorld Guest from 54.196.63.93
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

    
Need 301 redirect assist
jmueller0823



 
Msg#: 4641972 posted 10:20 pm on Feb 2, 2014 (gmt 0)

This redirect will be used on our host, WPEngine, using their redirect tool; in other words, I will not be placing this into an htaccess file. So, this needs to be a 301 redirect -- not a mod rewrite. Their tool allows me to input a 'source' and 'destination' ...

So, this is what I need to do:

``````````````````````````````````````````````````````
EXAMPLE
-- Source: /folder/*3847*.php
--Destination (redirect to): http://www.example.com/folder/folder/

``````````````````````````````````````````````````````
In the above example, I'm trying to capture source files such as:

john-smith-3847.php
jimmy-edward-olson-3847.php
starbucks3847.php

If the 'number' '3847' exists in the source filename, I need to redirect it.

Help, please! Thanks much.

Jim

[edited by: phranque at 6:10 am (utc) on Feb 3, 2014]
[edit reason] exemplified domain [/edit]

 

phranque

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



 
Msg#: 4641972 posted 8:51 pm on Feb 3, 2014 (gmt 0)

you can use regular expressions when specifying the Source.

Common Regex used for Redirect Rules | WordPress Hosting by @WPEngine:
http://wpengine.com/support/regex/ [wpengine.com]

jmueller

5+ Year Member



 
Msg#: 4641972 posted 9:22 pm on Feb 3, 2014 (gmt 0)

<< you can use regular expressions when specifying the Source.

Yes, I know : )

And what would that expression look like?
Thanks.

lucy24

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



 
Msg#: 4641972 posted 12:01 am on Feb 4, 2014 (gmt 0)

Can the "3487" ever be preceded by any other numeral? If not, you're looking at either \D (non-digit, not sure if Apache's RegEx engine supports this but it ought to) or [a-z-].

jmueller

5+ Year Member



 
Msg#: 4641972 posted 12:40 am on Feb 4, 2014 (gmt 0)

the numeric will be 2 to 4 digits.

Can you help me with the actual 'code' ? Thanks much.

lucy24

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



 
Msg#: 4641972 posted 1:10 am on Feb 4, 2014 (gmt 0)

By weird coincidence, it's less than 12 hours since I last posted the "Why We Make You Do It Yourself" boilerplate. It can't be more than two or three threads away.

Besides, you started out by saying that the code goes into a specific application-- I assume a control-panel type of thing?-- not into an Apache RewriteRule. So you'd need to consult the host for exact syntax.

I'm trying to capture source files such as:

I think here you don't mean "capture" in the regular expressions sense. You just mean that you need a pattern, right?

the numeric will be 2 to 4 digits.

Now, wait. What numeric? The part you've given as 3487? So it could be any number? Now I'm confused. What's the recurring part of the pattern you need to match?

jmueller0823



 
Msg#: 4641972 posted 3:07 am on Feb 4, 2014 (gmt 0)

Sorry, I'm not using the correct terms.

Yes, it is a control panel.

When we first started with this host, I imported our existing 301's (from htaccess) and the syntax looks like this:

Redirect 301 /folder/folder/filename.php http://www.example.com/folder/

I believe this is pretty typical, right?

```````````````````

I'll take another stab at explaining.

I discovered that for many of our articles, Google has indexed multiple filenames. I need to redirect these to the correct files.

What all of these filenames have in common is a 'number'; so rather than mess with all of the text and risk typos, I'll reference the numbers.


For example...

an-interview-with-tom-cruise-487.php
a-conversation-with-tom-cruise-487.php

For the two filenames above, we need to redirect to:

/tom-cruise-vanilla-sky/


So, to 'locate' the two source files, we need to look for *487.php

And the same scenario for other files.

I need a 'template' pattern (is that the right term?), where I create these 301's, and simply replace the number.

Make sense? Thanks much.
Jim

[edited by: phranque at 5:35 am (utc) on Feb 4, 2014]
[edit reason] Please Use example.com [webmasterworld.com] [/edit]

lucy24

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



 
Msg#: 4641972 posted 4:04 am on Feb 4, 2014 (gmt 0)

It all depends whether your control-panel-thingie uses conventional regular expressions or some other formulation.

an-interview-with-tom-cruise-487.php
a-conversation-with-tom-cruise-487.php

both =
^\D+487\.php
or
^[a-z-]+487\.php

john-smith-3847.php
jimmy-edward-olson-3847.php
starbucks3847.php

all =
\D+3847\.php
[a-z-]+3847\.php

The form \D means "non-digit". Saves you a few bytes if you can do it this way.

But if the things you've rendered as numbers are really some random bit of text, there may not be any way to avoid a little backtracking.

jmueller0823



 
Msg#: 4641972 posted 12:26 am on Feb 5, 2014 (gmt 0)

thank you!

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4641972 posted 3:26 pm on Feb 5, 2014 (gmt 0)

It is usually a very good idea to use a RewriteRule with the [R=301,L] flags rather than the Redirect directive. This is essential if you already have any other rules utilising RewriteRules.

jmueller

5+ Year Member



 
Msg#: 4641972 posted 3:42 pm on Feb 5, 2014 (gmt 0)

Thank you...

lucy24

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



 
Msg#: 4641972 posted 8:11 pm on Feb 5, 2014 (gmt 0)

Backtracking...

this needs to be a 301 redirect -- not a mod rewrite


This was meaningless at the outset. A 301 redirect is an end. mod_rewrite is the means. One can only hope that the host's internal redirect tool uses mod_rewrite or mod_alias appropriately. One or the other, not both.

jmueller

5+ Year Member



 
Msg#: 4641972 posted 8:16 pm on Feb 5, 2014 (gmt 0)

Yea, no idea.

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