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

    
Please check my rewite rule - new page location
Seelife




msg:4582572
 4:37 pm on Jun 9, 2013 (gmt 0)

Hi Folks, I am sorry as I know that similar posts have addressed this. I think have the solution but an reluctant to mess with the backed before checking - Im not a developer. As this is between a live and development site. I have a live site (Joomla) on a subfolder with many articles. We have a new development site where we have a new Joomla install (upgrade) on a different subfolder and imported all articles(pages).

So our OLD pages are like :
http://www.website.com/MJ/hospitality/hospitality-news/hotel-industry/1679-an-article-title

Our NEW pages are like :
http://www.website.com/MA/index.php/hospitality/hospitality-news/hotel-industry/1679-an-article-title


There are a few hundred pages in this format.
So hope I can have a general rule as follows - BUT - is it correct?

RewriteEngine on
RewriteRule ^/?MJ([a-z/.]*)$ /MA/index.php$1 [R=301,L]

Thanks for your input.

 

lucy24




msg:4582601
 8:25 pm on Jun 9, 2013 (gmt 0)

^/?

A request either will or will not have a leading slash. In the config file it has a slash. In htaccess --also in Directory envelopes within config-- it does not. Unless the request somehow sneaked in with a double slash after the hostname. (I've only seen this once or twice; the server didn't seem to bat an eye. It's one of many malformed-request patterns that you don't need to deal with unless and until they become a problem.)

MJ([a-z/.]*)$

This form will exclude ALL requests, because your URLs contain numbers. Since the literal text you're matching comes at the very beginning of the request, you can use a simple .* for the rest. Or probably .+ since a request containing nothing after /MJ would not go far.

But before you go there...
Is it too late to have another look at your "new" URL format? It's almost always a bad sign when the new URL is longer and/or less pretty than the old URL. And anything with "index.php" in the exact center is doubly egregious. Obviously this is not a physical path; things will get rewritten at some later point. So at a minimum, why not leave out the "index.php" entirely?

Seelife




msg:4582609
 9:39 pm on Jun 9, 2013 (gmt 0)

Hi Lucy24, thanks for the feedback - the code I have is adapted from an example I found. Following your comments I have found some problems I have now fixed - THANKS !
The site is a Joomla 2.5 site. I found I had not properly renamed the htaccess from txt had also not turned on rewrites in Joomla (sorry)

The now correct joomla URLs now look like this :
http://www.website.com/MA/hospitality/hospitality-news/hotel-industry/1679-an-article-title


Can you please suggest the correct format for the rewrite rule - much appreciated

lucy24




msg:4582663
 3:39 am on Jun 10, 2013 (gmt 0)

Can you please suggest the correct format for the rewrite rule

Not without knowing what they're getting rewritten to and from!

Oh, wait, you mean the surface redirect.

old format from first post:
MJ/hospitality/hospitality-news/hotel-industry/1679-an-article-title

new format from follow-up post:
MA/hospitality/hospitality-news/hotel-industry/1679-an-article-title

You mean they're exactly the same except that they used to start in MJ and now they start in MA? Can't you persuade your joomla installation to leave off that part too, if it's always the same?

If not, you're essentially using the rule you started out with-- minus the "index.php" in the middle (whew!).

Assuming ALL URLs in "MJ" will henceforth be "MA" instead, it now becomes simply

RewriteRule ^MJ/(.*) http://www.example.com/MA/$1 [R=301,L]

Opening anchor is crucial, but you don't need a closing anchor: the RewriteRule will happily capture anything and everything that comes after the leading /MJ

Then again, if you spent a little more time getting chummy with your RewriteRules, you could almost certainly dispense with the redirect altogether. It doesn't seem to do anything, so why not keep the original URL and tweak the rewrite instead? (The rule that takes your pretty URLs and changes them into something joomla can read.)

Seelife




msg:4582868
 5:43 pm on Jun 10, 2013 (gmt 0)

Hi Lucy24, I will do as you say and try to get friendly with the rules. Thanks for helping out - one last question - I assume the rule you suggest will keep google happy and link juice flowing from the old links.
Forgive me if I am slow (Im not an experienced developer). The new site I have built has some plugins etc that dont like being "moved" so I decided to 301 redirect from the old site to the new site (on the new folder).
Im happy to consider alternatives but my main objective was to keep traffic from already well indexed pages flowing thro to the new sites articles without getting error and google objecting etc.
Regards

lucy24




msg:4582918
 8:26 pm on Jun 10, 2013 (gmt 0)

If you can't manage a behind-the-scenes rewrite (i.e. no URL change), a one-on-one, page-for-page redirect is a strong second choice.

Seelife




msg:4582931
 9:28 pm on Jun 10, 2013 (gmt 0)

Am I missing something - doesnt the rewrite rule you suggest - match pages ie if google sends a visitor to an /MJ/etc/page then the rewrite magically makes it go to the new page by substituting the /MA/etc so you end up on the new page (ie google doesnt care or know until it picks up and indexes the new location)- sorry to be dense.

lucy24




msg:4582940
 11:11 pm on Jun 10, 2013 (gmt 0)

doesnt the rewrite rule you suggest - match pages

Yes. If you were very chummy with mod_rewrite you could achieve the same thing without changing URLs. But a single-step redirect if fine.

You may be tripping over terminology. A redirect = URL changes. A rewrite = URL stays the same, while server fetches content from elsewhere. Both of those are functions, not modules. You can use mod_rewrite to create a redirect. That's what you are doing here.

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