rewrite works, but causes site problems :/

New to mod_rewrite? This is a good place to start.

rewrite works, but causes site problems :/

Postby alessa » Fri Oct 09, 2009 1:07 am

hi!
the website im working on uses joomla as a cms, but i decided not to use the joomla-seo urls, instead rewrite the urls myself. the rewrite itself works perfectly, but causes some parts of the site to malfunction. I'm not sure if its a joomla compatibility problem or if my rules are wrong. heres my .htaccess

Code: Select all
Options +FollowSymLinks

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php\?option=com_content&view=article&id=2&Itemid=2
RewriteRule ^index\.php$ /Company/? [L,R=301]
RewriteRule ^(Company|company)/$ /index.php?option=com_content&view=article&id=2&Itemid=2 [L]


As mentioned, the rewrite works fine for the "Company"-page but suddenly one of my flash files doesnt work right (I think it might have a wrong path to its xml source) and the joomla menu doesnt recognize what page has been called (some variable "current" is set to default/home ). is this a problem in my rewriting rule(s)?

thanx 4 the help,
alessa
alessa
 
Posts: 3
Joined: Fri Oct 09, 2009 12:43 am

Postby richardk » Fri Oct 09, 2009 8:12 am

I doubt it's the mod_rewrite.

As mentioned, the rewrite works fine for the "Company"-page but suddenly one of my flash files doesnt work right (I think it might have a wrong path to its xml source)

Just within that page, right? Are the paths relative? FAQ: Relative paths to images, JavaScript, CSS and other external/linked files are broken.

and the joomla menu doesnt recognize what page has been called (some variable "current" is set to default/home ).

What should the value be?
What sets that variable?


Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Match the variables in any order.
RewriteCond %{QUERY_STRING} ^(.*&)?option=com_content(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?view=article(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?id=2(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?Itemid=2(&.*)?$ [NC]
RewriteRule ^(index\.php)?$ http://www.example.com/Company/? [NC,R=301,L]

RewriteCond %{HTTP_HOST} ^(example\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]

RewriteRule ^company/$ /index.php?option=com_content&view=article&id=2&Itemid=2 [NC,QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby alessa » Fri Oct 09, 2009 10:05 am

ok, thanks for the try, but your code causes a loop error.

the errors with my code occur only the /Company site. Actually im not at all sure if its the path to the xml. the flash application gets stuck on the first frame, without throwing an error. the path thing was just a theory :)

i dont know much about the joomla variable "current" or where it comes from. the GET variables all echo correctly on the malfunctioning site.

:(
alessa
 
Posts: 3
Joined: Fri Oct 09, 2009 12:43 am

Postby richardk » Fri Oct 09, 2009 12:45 pm

ok, thanks for the try, but your code causes a loop error.

Oh, yeah. It needs
Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS} ^$

before
Code: Select all
RewriteCond %{QUERY_STRING} ^(.*&)?option=com_content(&.*)?$ [NC]


the errors with my code occur only the /Company site. Actually im not at all sure if its the path to the xml. the flash application gets stuck on the first frame, without throwing an error. the path thing was just a theory

And it doesn't without the mod_rewrite?

i dont know much about the joomla variable "current" or where it comes from. the GET variables all echo correctly on the malfunctioning site.

Does it use the REQUEST_URI variable at all, that might be part of the problem (the REQUEST_URI being /company/).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby alessa » Fri Oct 09, 2009 1:25 pm

ok, now your code shows the exact same simptoms as my original code.

the page works fine without mod_rewrite. infact the exact same flash file and menu work perfectly on the pages without mod_rewrite, so it must have something to do with it.

about the request_uri:

i echoed it and it had the value "/Company/" ,
so inserted the following code:

Code: Select all
$_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'],1 );
          if (isset($_SERVER['QUERY_STRING'])) { $_SERVER['REQUEST_URI'].='?'.$_SERVER['QUERY_STRING']; }


this changed the value of request_uri to "index.php?option=com_content&view=article&id=2&Itemid=2"

i thought that was a really smart move but unfortunately the problem remains... any other ideas?

cheers, alessa


edit: ok, it seems that i just misplaced the above code. now i put it in a different place, and the menu works perfectly now! in case anyone else ever stumbles over this problem:
put the above code in the very beginning of the index.php in the joomla root directory, not in the template one (obviously :wink: ).

the flash file was still messed up, so i tested my path-theory. i created a folder called /Company and put the flash and xml file in it, and now it works as well!!! i will rewrite my flashfile to look for the absolute path on the server.

all problems solved i guess!!!

thanks a million richardk. great help! sometimes it just needs a second mind to find the problem..

edit nr2:
unfortunately i was a little quick on cheering. what happened was that when i was on the mod_rewritten page the "home"-link in the menu suddenly pointed to www.example.comindex.php/

no idea how that happened XD

for now i chose the following solution:

i added some code in /modules/mod_mainmenu/helper.php right where the main menu ul is generated:

Code: Select all
...
// Print a link if it exists
      if ($tmp->url != null)
      {
         // Handle SSL links
         $iSecure = $iParams->def('secure', 0);
         if ($tmp->home == 1) {
            $tmp->url = JURI::base();
         } elseif (strcasecmp(substr($tmp->url, 0, 4), 'http') && (strpos($tmp->link, 'index.php?') !== false)) {
            $tmp->url = JRoute::_($tmp->url, true, $iSecure);
         } else {
            $tmp->url = str_replace('&', '&', $tmp->url);
         }

// added code starts here! ---------------------

if ($tmp->url=="http://www.example.comindex.php/") { $tmp->url="http://www.example.com/"; }

// added code ends here! ---------------------

         switch ($tmp->browserNav)
         {
            default:
            case 0:
               // _top
               $data = '<a href="'.$tmp->url.'">'.$image.$tmp->name.'</a>';
               break;
            case 1:
               // _blank
               $data = '<a href="'.$tmp->url.'" target="_blank">'.$image.$tmp->name.'</a>';
               break;
            case 2:
               // window.open
               $attribs = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,'.$this->_params->get('window_open');

               // hrm...this is a bit dickey
               $link = str_replace('index.php', 'index2.php', $tmp->url);
               $data = '<a href="'.$link.'" onclick="window.open(this.href,\'targetWindow\',\''.$attribs.'\');return false;">'.$image.$tmp->name.'</a>';
               break;
         }
      } else
...


the commented part is the added code. its a very bad solution, it will probably be overwritten when joomla is updated, but for now it works fine.

i'll post a better solution once i find one...

cheers, alessa
alessa
 
Posts: 3
Joined: Fri Oct 09, 2009 12:43 am

Postby richardk » Sat Oct 10, 2009 10:01 am

I think it should be /index.php?.... Try replacing
Code: Select all
,1 );

with
Code: Select all
,0 );


Or try replacing
Code: Select all
$_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'],1 );
          if (isset($_SERVER['QUERY_STRING'])) { $_SERVER['REQUEST_URI'].='?'.$_SERVER['QUERY_STRING']; }

with
Code: Select all
if(strcasecmp($_SERVER['REQUEST_URI'], '/company/') === 0)
{
  $_SERVER['REQUEST_URI'] = '/index.php?option=com_content&view=article&id=2&Itemid=2';
}
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 28 guests

cron