Forum Moderators: phranque

Message Too Old, No Replies

Site Redesign with Joomla in subdirectory and 301 rewrites not working

Site Redesign with Joomla in subdirectory and 301 rewrites not working

         

thatgirl

6:38 am on Mar 9, 2012 (gmt 0)

10+ Year Member



I apologize if these issues have been covered somewhere else...I am fairly new at working with the .htaccess file and have spent days researching and troubleshooting possible solutions but nothing seems to work...and I can't seem to find the exact scenario that applies to me. It also is a long post but I tried to be thorough and include code so as to not waste anyone's time by giving you insufficient info.

I have redesigned a website and to minimize any search engine problems I need to configure my .htaccess file to redirect my old page urls to my new page urls. However, there are several other issues to consider which has me confused:

* Root level contains the new html website which links to new Joomla content;
* new Joomla is installed in the subdirectory /menus;
* new Joomla has SEF urls and mod_rewrite enabled;
* old Joomla which is installed in the subdirectory /cms used long dynamic urls (query strings);
* there are some canonical issues going on and the old Joomla page urls which need to be redirected or rewritten are non-www while the new Joomla site's page urls are www;
* I don't want the old site to remain visible so my plan was to either delete the /cms folder or block it from Google by password protecting it.

I have been successful with my .htaccess file rewriting my urls to sef urls in my new joomla install located in my /menus directory. This .htaccess file is located in the /menus folder and the code is below.

I also tested the code to rewrite the non-www versions of the website to www and I also was successful. I placed this file in the root directory. I removed it for now until I get the url redirect working which is most important.

PROBLEM > I have tried all types of code in the .htaccess file and have placed it at the root and/or in the /menus and /cms directories and I haven't been able to redirect the old content page urls to the new content page urls. It doesn't work...nothing happens.

The code I was using for this was:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} ^option=com_content&task=view&id=21&Itemid=34$
RewriteRule ^/index.php$ [domain.com...] [R=301,L]

I tried this in the .htaccess file in the /cms directory first and then tried putting this code in the .htaccess file at the root level (but added /cms in front of the /index)...it didn't work either way. Would it matter if the old page url doesn't have the www and the new page url does?

The code which is currently included in the .htaccess file in the new joomla directory /menus is below:

##
# @packageJoomla
# @copyrightCopyright (C) 2005 - 2012 Open Source Matters. All rights reserved.
# @licenseGNU General Public License version 2 or later; see LICENSE.txt
##

##
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
#
# The line just below this section: 'Options +FollowSymLinks' may cause problems
# with some server configurations. It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that dissallows changing it in
# your .htaccess file. If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url's. If they work,
# it has been set by your server administrator and you do not need it set here.
##

## Can be commented out if causes errors, see notes above.
Options +FollowSymLinks

## Mod_rewrite in use.

RewriteEngine On

## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site block out the operations listed below
# This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.

## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
## End - Custom redirects

##
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).
##

# RewriteBase /

## 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 something within the component folder,
# or 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))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file 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.


Thanks for any help provided...I have exhausted myself and am just about to give up. I have 3 locations to choose from...the root, /cms and /menus...that I could put the htaccess file in and I am having trouble figuring if everything can go into one file or if it needs to be split up so there are no conflicts and if so what code goes where and what order or protocol is used.

lucy24

11:24 am on Mar 9, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Would it matter if the old page url doesn't have the www and the new page url does?

No, mod_rewrite doesn't know from domains unless you put something explicit in a condition.

One thing did jump out at me. Oops, no, two things. The second one jumped up and down hysterically and waved its arms when I went to check on the first one ;)

Potential problem:
RewriteCond %{QUERY_STRING} ^option=com_content&task=view&id=21&Itemid=34$

The query string is anchored at both ends and it lists four queries with precise values. Will it always come in this way, with exactly those four items in exactly that order?

Very likely problem:
RewriteRule ^/index.php$

In most Apache installations this Rule will only apply if the request is for
www.example.com//indexNphp
because the leading slash is dropped. And, equally important, what if the request isn't for "index.php" but simply the domain name?

I said "indexNphp" because your un-escaped period means that anything could go in that location. This will not cause the rule to fail, but can lead to unwanted effects if someone deliberately requests a bogus URL. I think what you really want is

^(index\.php)?$


Hey, as long as we're talking about joomla, you don't happen to know what (if anything) K2 means do you? I met it the other day-- many times-- on a group of joomla pages, and all I can say for sure is that it didn't belong. At least not in plain sight rather than hidden in the code.

thatgirl

8:29 pm on Mar 9, 2012 (gmt 0)

10+ Year Member



To answer your questions:

Will it always come in this way, with exactly those four items in exactly that order?

>Yes...that is a page in the old site...one of the restaurant's menus...and I need to redirect this page to the new designed menu page using the new Joomla installed in /menus. I only have about 5 pages that I need to 301 redirect, I just can't get it to work.

Very likely problem:
RewriteRule ^/index.php$
And, equally important, what if the request isn't for "index.php" but simply the domain name?

> I am not sure I quite understand, but I am going to try your code (^(index\.php)?$) to see if that works.
Bottom line is I need this old page or url [samedomain.com...] to go to this new page or url [samedomain.com...]

I also need the www version of the old page url to go to the new page as well.

>My question is where would I put the revised code you gave me?...in a htaccess file in the root level and leave the above htaccess code for new Joomla in the /menus directory?
___________________

As for K2, K2 was built as a complete replacement of the default article system in Joomla!. You install it like any Joomla! extension, import your articles from the default Joomla! article system and you instantly get a host of new features for your existing content: rich content forms for items (think of Joomla! articles with additional fields for article images, videos, podcasts & other audio files, image galleries and attachments), hassle-free image management (uploaded item images are auto-resized to 6 configurable dimensions, either globally or per category - eliminating your need to Photoshop resize), comments, tagging, built-in options to extend content forms (e.g. to create product catalogs), powerful content modules fetching K2 content in any way you can imagine, frontend editing with easy to use access control settings (for content-heavy websites), powerful yet easy templating (and sub-templating) for going above the "Joomla! average", extended user profiles, user groups, blogs, a powerful plugin API to extend item/category/user forms, "drag and drop" media manager etc.

I have installed it on several of my clients sites but then didn't end up using it because I was able to do what I needed to with core Joomla! and didn't need the added features. New Joomla 2.5 has added even more features and has ironed out some of the frustrating formatting issues from a design and usability perspective making it easier to get what you want or need. Depending on the size of the site, K2 would be advantageous because things are localized and features can be applied globally or to groups of items which obviously would save time.

thatgirl

8:36 pm on Mar 9, 2012 (gmt 0)

10+ Year Member



btw...you shouldn't have seen K2 in plain sight...

I just noticed that my urls above were abbreviated, here they are
old url "http://same domain.com/cms/index.php?option=com_content&task=view&id=21&Itemid=34"

needs to go to
new url "http://www.same domain.com/menus/food/bread.html"

g1smd

8:51 pm on Mar 9, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Use example.com in this forum as per RFC 2606 and the URL auto-linking is suppressed.


RewriteRule ^/index.php$
.... should be
RewriteRule ^oldcms/index\.php$
....
and put the code in the root htaccess file.

Actually, I prefer
RewriteRule ^oldcms/(index\.php)?$
... which also matches bare folder requests without filename but with parameters.