| 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.)
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?
| 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 :
Can you please suggest the correct format for the rewrite rule - much appreciated
| 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:
new format from follow-up post:
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.)
| 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.
| 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.
| 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.
| 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.