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

    
Can't make simple rewrite rule work! Can't see error!
Rewrite URI 1 to URI 2
snowweb

5+ Year Member



 
Msg#: 4430241 posted 5:40 am on Mar 17, 2012 (gmt 0)

I'm replace a website with one based on a different CMS and therefore the URL formats are different. The support within the new CMS doesn't seem able to do exactly what I need so I'm planning to use mod_rewrite for URL rewriting of the existing URL's.

Actually, there are only about four really important ones and I'm just trying to get one working first.

Currently I have http://OLD-SITE.mydomain.com/index/content/2550M-Rev07/ This actually points to a a php file due to URL rewriting on the domain and works fine. It has a good Google ranking which I don't want to lose. To be clear, we are concerned with this document only. We're not looking for pattern matching.

My new site also has the same document on it and is accessible using either
http://NEW-SITE.mydomain.com/our-services/bir-forms/2550m or
http://NEW-SITE.mydomain.com/index.php?option=com_content&view=article&id=10&Itemid=22

I need to make it accessible on http://NEW-SITE.mydomain.com/index/content/2550M-Rev07/

When a user types the above URL into his browser, I don't want the browser to be redirected. The URL in the address bar, must continue to read as above and the page shown.

In order to accomplish the above, I have tried the following as my .htaccess file, but I am served a Joomla 404 Componentent not found page (same as I get if I visit a non-existent URL on the domain).

.htaccess
RewriteEngine On

IndexIgnore *
Options +FollowSymLinks All -Indexes +MultiViews

RewriteRule ^/index/content/2550M-Rev07/$ /index.php?option=com_content&view=article&id=10&Itemid=22 [L]


########## Begin - Joomla! core SEF Section

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for the site root, or for an extensionless URL,
# or the requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw|ini|zip|json|file))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]

########## End - Joomla! core SEF Section


Any pointers would be much appreciated.

Kind regards,

Peter

 

lucy24

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



 
Msg#: 4430241 posted 7:44 am on Mar 17, 2012 (gmt 0)

RewriteRule ^/index/content/2550M-Rev07/$ /index.php?option=com_content&view=article&id=10&Itemid=22 [L]


Get rid of the leading slash in the pattern. mod_rewrite strips away the slash at the end of the domain name, so the pattern will only work for malformed URLs like "example.com//pagename".* But keep the leading slash in the target, where you've got it.

g1 will show up presently and have something to say about the wisdom of letting the same page be reached via three different URLs ;)


* After saying this in zillions of posts, I actually got a request in this form the other day. It looks as if the person-- definitely human-- pasted their desired page name into the browser's address bar but missed a slash. There's an obscure HTTP rule that collapses multiple slashes-- with the further weird effect that all the relatively-linked images also came through with leading double //

snowweb

5+ Year Member



 
Msg#: 4430241 posted 9:36 am on Mar 17, 2012 (gmt 0)

Get rid of the leading slash in the pattern. mod_rewrite strips away the slash at the end of the domain name, so the pattern will only work for malformed URLs like "example.com//pagename".* But keep the leading slash in the target, where you've got it.


Thanks Lucy! I've just amended my htaccess removing that first slash in the pattern.

Unfortunately, it didn't work. http://joomla.bookkeeper.ph/index/content/2550M-Rev07/ still goes to 404.

Regarding the additional urls for each page. I understand the importance of removing those before the site goes live. Google must only ever encounter one url for each page. I'm just leaving that until last.

Do you have any other thoughts on what I might be doing wrong here please?

Kind regards,

Peter

lucy24

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



 
Msg#: 4430241 posted 11:32 am on Mar 17, 2012 (gmt 0)

Oops. Brain cells just nipped out for a quick smoke.

But try this for testing purposes: Change the rewrite to a redirect with the [R=301,L] flag. When you get your 404 page, see what the browser's address bar says. This is the quickest way to tell if the rewrite has actually happened. And then you can figure out if the problem is with the rule or with the target page.

Don't forget to delete the R=301 as soon as you've checked!

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