301 Redirect dynamic URL matching expression - please help

Ant,

Would you PLEASE address:

  1. The duplicated Itemid=65 in your query string?

  2. Is this whole query string generated?

  3. Is it generated as “page=checkout.index&option=com_virtuemart&Itemid=65&redirected=1&Itemid=65”?

  4. Does the generated link include the nl subdirectory?

Regards,

DK

I’m using Joomla as a CMS with Artio Joomsef so the URLs are generated automatically.

1.) This is how it is generated and it seems to pick up this string to refer it.

2.) Everything hsould be generated as it’s a CMS.

3.) Without the space 5 at the end yes. That’s the url after the ?

4.) I’m not sure what you mean, the generated link that I’m trying to change does include the nl/ subdirectory in that it is www.seed-city.com/nl/index.php?page=checkout.index&option=com_virtuemart&Itemid=65&redirected=1&Itemid=65

Thanks again. Ant.

I’m sorry if my answers seem ill thought out, it’s just I’m very new to HTaccess and URL rewriting.

Ant,

Okay, it’s just hard to believe that the CMS (even Joomla) would add a key/value pair to a query string twice and the errant space was my typo.

4.) I’m not sure what you mean, the generated link that I’m trying to change does include the nl/ subdirectory in that it is www.seed-city.com/nl/index.php?page=checkout.index&option=com_virtuemart&Itemid=65&redirected=1&Itemid=65

It’s just I want to specify that there has to be a nl/ ja/ de/ preceding the index.php

Do you see from these two quotes why I’m confused? The earlier one (listed second) says that you want to insert a language subdirectory while the current one (the first listed above) says that you want to eliminate the language subdirectory. You really can’t have it both ways, can you?

Okay, to remove the nl subdirectory would be merely to use the code already provided above, i.e.,

RewriteCond %{QUERY_STRING} ^page=checkout.index&option=com_virtuemart&Itemid=65&redirected=1&Itemid=65$
RewriteRule ^nl/index\\.php$ index.php [R=301]

The R=301 would force Apache to display the redirection without the nl subdirectory but it would only work if index.php is in the DocumentRoot (the same directory as the .htaccess file).

To add the nl subdirectory is possible but would force your ja and de speakers to view the dutch language pages. If you were going to add a language specification, you need to provide SOMETHING to mod_rewrite to let it know which language to specify. As an aside, though, mod_negotiation is designed to handle that exact question as, from memory, it gets the preferred language from the visitor’s browser and attempts to match that in your site’s files. Because I’m firmly rooted in English, though, I’m of little use in guiding you through mod_negotiation.

Ill thought out? No, it’s merely a matter of communications - and I’ve already admitted to being firmly rooted in English (despite years of language classes). So long as I can explain what’s needed so you can understand, we’re all set.

RewriteCond %{QUERY_STRING} ^page=checkout.index&option=com_virtuemart&Itemid=65&redirected=1&Itemid=65$
RewriteRule ^/?index\\.php$ nl/index.php [R=301]

Note, please, that I’ve added /? after the ^ to cover both versions of Apache - Apache 1.x requires / after the ^ while Apache 2.x forbids the /.

WARNING: If Joomla is automatically generating the language subdirectory, please check the Joomla documentation as it would presumably accommodate that with its index.php file (as well as its own mod_rewrite code). Messing about with CMS can be very dangerous!

Regards,

DK

Hello, I don’t want to add nl/ or /de or ja/, I want to remove it. When I said “It’s just I want to specify that there has to be a nl/ ja/ de/ preceding the index.php” what I meant was that I want to specify that there has to be a nl/ ja/ de/ preceding the index.php for the redirection to take place not that there has to be nl/ ja/ de/ prededing the index.php at the end of the redirection.

I’ve tried

RewriteCond %{QUERY_STRING} ^page=checkout.index&option=com_virtuemart&Itemid=65&redirected=1&Itemid=65$
RewriteRule ^nl/index\\.php$ index.php [R=301]

but it doesn’t redirect. I’m still seeing a blank white page. I’ve placed a copy of the htaccess file in the same folder as the index.php I’m using but still no luck :frowning:

There’s one index.php in the root folder and another in /templates/cityseeds/. I’ve got the htaccess file in both.

Thanks again. Ant.

Here is my entire current htaccess file :

##
# @version $Id: htaccess.txt 9975 2008-01-30 17:02:11Z ircmaxell $
# @package Joomla
# @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
# @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
# Joomla! is Free Software
##


#####################################################
#  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 disallows 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
# gtranslate config
        RewriteRule ^([a-z]{2})/(.*)$ /gtranslate/translate.php?lang=$1&url=$2 [L,QSA]
        RewriteRule ^([a-z]{2})$ /gtranslate/translate.php?lang=$1 [L,QSA]
        RewriteRule ^(zh-CN)/(.*)$ /gtranslate/translate.php?lang=$1&url=$2 [L,QSA]
        RewriteRule ^(zh-CN)$ /gtranslate/translate.php?lang=$1 [L,QSA]
        RewriteRule ^(zh-TW)/(.*)$ /gtranslate/translate.php?lang=$1&url=$2 [L,QSA]
        RewriteRule ^(zh-TW)$ /gtranslate/translate.php?lang=$1 [L,QSA]


redirect 301 /cs/cart http://www.seed-city.com/cart
redirect 301 /zh-CN/cart http://www.seed-city.com/cart
redirect 301 /af/cart http://www.seed-city.com/cart
redirect 301 /nl/cart http://www.seed-city.com/cart
redirect 301 /fr/cart http://www.seed-city.com/cart
redirect 301 /de/cart http://www.seed-city.com/cart
redirect 301 /ja/cart http://www.seed-city.com/cart
redirect 301 /pt/cart http://www.seed-city.com/cart
redirect 301 /ru/cart http://www.seed-city.com/cart
redirect 301 /es/cart http://www.seed-city.com/cart


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

RewriteBase /
RewriteEngine On
RewriteCond %{QUERY_STRING} ^page=checkout.index&option=com_virtuemart&Itemid=65&redirected=1&Itemid=65$
RewriteRule ^nl/index\\.php$ index.php [R=301]
RewriteCond %{HTTP_HOST} ^seed-city.com$
RewriteRule ^(.*)$ "http\\:\\/\\/www\\.seed-city\\.com$1" [R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\\.php|\\.html|\\.htm|\\.feed|\\.pdf|\\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
########## Begin - Joomla! core SEF Section
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\\.php|\\.html|\\.htm|\\.feed|\\.pdf|\\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#
########## End - Joomla! core SEF Section


########## 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 set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\\(.*\\) [OR]
# Block out any script that includes a  tag in URL
RewriteCond %{QUERY_STRING} (\\|%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})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
#
########## End - Rewrite rules to block out some common exploits

Ant,

Order is everything with code and the Joomla code will match and redirect before the code we created - which is a good thing as Joomla’s code is what enables your translations. AGAIN, if you move our code before the Joomla code, you will DISABLE your translations.

Regards,

DK

OK, so do you think it’s possible to redirect the URL or is htaccess too limited to be able to match both the string and the created subfolder? Thanks, Ant.

Ha, you were right about the order. Moving the code up to first worked and everything is fine now with translation working :slight_smile:

##
# @version $Id: htaccess.txt 9975 2008-01-30 17:02:11Z ircmaxell $
# @package Joomla
# @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
# @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
# Joomla! is Free Software
##


#####################################################
#  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 disallows 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
RewriteCond %{QUERY_STRING} ^page=checkout.index&option=com_virtuemart&Itemid=65&redirected=1&Itemid=65$
RewriteRule ^cs/index\\.php$ index.php [R=301]
RewriteCond %{QUERY_STRING} ^page=checkout.index&option=com_virtuemart&Itemid=65&redirected=1&Itemid=65$
RewriteRule ^zh-CN/index\\.php$ index.php [R=301]
RewriteCond %{QUERY_STRING} ^page=checkout.index&option=com_virtuemart&Itemid=65&redirected=1&Itemid=65$
RewriteRule ^af/index\\.php$ index.php [R=301]
RewriteCond %{QUERY_STRING} ^page=checkout.index&option=com_virtuemart&Itemid=65&redirected=1&Itemid=65$
RewriteRule ^nl/index\\.php$ index.php [R=301]
RewriteCond %{QUERY_STRING} ^page=checkout.index&option=com_virtuemart&Itemid=65&redirected=1&Itemid=65$
RewriteRule ^fr/index\\.php$ index.php [R=301]
RewriteCond %{QUERY_STRING} ^page=checkout.index&option=com_virtuemart&Itemid=65&redirected=1&Itemid=65$
RewriteRule ^de/index\\.php$ index.php [R=301]
RewriteCond %{QUERY_STRING} ^page=checkout.index&option=com_virtuemart&Itemid=65&redirected=1&Itemid=65$
RewriteRule ^ja/index\\.php$ index.php [R=301]
RewriteCond %{QUERY_STRING} ^page=checkout.index&option=com_virtuemart&Itemid=65&redirected=1&Itemid=65$
RewriteRule ^pt/index\\.php$ index.php [R=301]
RewriteCond %{QUERY_STRING} ^page=checkout.index&option=com_virtuemart&Itemid=65&redirected=1&Itemid=65$
RewriteRule ^ru/index\\.php$ index.php [R=301]
RewriteCond %{QUERY_STRING} ^page=checkout.index&option=com_virtuemart&Itemid=65&redirected=1&Itemid=65$
RewriteRule ^es/index\\.php$ index.php [R=301]
# gtranslate config
        RewriteRule ^([a-z]{2})/(.*)$ /gtranslate/translate.php?lang=$1&url=$2 [L,QSA]
        RewriteRule ^([a-z]{2})$ /gtranslate/translate.php?lang=$1 [L,QSA]
        RewriteRule ^(zh-CN)/(.*)$ /gtranslate/translate.php?lang=$1&url=$2 [L,QSA]
        RewriteRule ^(zh-CN)$ /gtranslate/translate.php?lang=$1 [L,QSA]
        RewriteRule ^(zh-TW)/(.*)$ /gtranslate/translate.php?lang=$1&url=$2 [L,QSA]
        RewriteRule ^(zh-TW)$ /gtranslate/translate.php?lang=$1 [L,QSA]


redirect 301 /cs/cart http://www.seed-city.com/cart
redirect 301 /zh-CN/cart http://www.seed-city.com/cart
redirect 301 /af/cart http://www.seed-city.com/cart
redirect 301 /nl/cart http://www.seed-city.com/cart
redirect 301 /fr/cart http://www.seed-city.com/cart
redirect 301 /de/cart http://www.seed-city.com/cart
redirect 301 /ja/cart http://www.seed-city.com/cart
redirect 301 /pt/cart http://www.seed-city.com/cart
redirect 301 /ru/cart http://www.seed-city.com/cart
redirect 301 /es/cart http://www.seed-city.com/cart


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

RewriteBase /
RewriteEngine On
RewriteCond %{HTTP_HOST} ^seed-city.com$
RewriteRule ^(.*)$ "http\\:\\/\\/www\\.seed-city\\.com$1" [R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\\.php|\\.html|\\.htm|\\.feed|\\.pdf|\\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
########## Begin - Joomla! core SEF Section
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\\.php|\\.html|\\.htm|\\.feed|\\.pdf|\\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#
########## End - Joomla! core SEF Section


########## 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 set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\\(.*\\) [OR]

Thanks for your time and patience. Ant.