homepage Welcome to WebmasterWorld Guest from 54.205.95.9
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe and Support WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Mod rewrite for joomla
mod_rewrite error
Anojan Sivarajah




msg:4451643
 3:42 am on May 10, 2012 (gmt 0)

my site is sef enabled and done in joomla.

what i need is a rewrite rule so

http://www.example.com/fr/corporate/news points to http://www.example.com/corporate/news/?lang=fr

i tried few url rewrite rules but it generates 404 error category not found page. i believe it looks for thr fr folder or a category called fr.


i have a rule which is

RewriteRule ^/([a-z][a-z])/(.*) /$2/?lang=$1 [R=301,L]

but this changes the value in the address bar. without r=301 it doesn't work at all

[edited by: incrediBILL at 4:10 am (utc) on May 10, 2012]
[edit reason] fixed URLS, use Example.com [/edit]

 

Anojan Sivarajah




msg:4451655
 5:12 am on May 10, 2012 (gmt 0)

if i turn off sef in joomla admin my rewrite rule works. but my entire site is made in a way that the site won't function without sef

lucy24




msg:4451692
 7:54 am on May 10, 2012 (gmt 0)

You need to look at your existing rewrites. Any new rewrites have to add to what's there, not create a conflict.

what i need is a rewrite rule so

http://www.example.com/fr/corporate/news points to http://www.example.com/corporate/news/?lang=fr

i tried few url rewrite rules but it generates 404 error category not found page. i believe it looks for thr fr folder or a category called fr.


Can we assume for the sake of discussion that when you say "points to" you mean "serves content from"? If so, it has to be set up as a Rewrite (without protocol and domain), not a Redirect.

If the server is looking for a /fr/ directory, then the rewrite/redirect isn't happening.

Simple test: Set up your ordinary RewriteRule, but add the [R=301] flag. Now your browser's address bar will tell you if the rule has executed. This is independent of whether the target URL really exists. Even if you land on your 404 page, the address bar will say where the browser "thinks" it is.

The target
/corporate/news/?lang=fr
means:

go to the real location
/corporate/news/index.php
and do stuff with the query "lang=fr"

We really need to see what RewriteRules you have tried. And probably also the other Rewrites, because everything has to happen in a particular order.

Anojan Sivarajah




msg:4451693
 7:57 am on May 10, 2012 (gmt 0)

With joomla sef turned off the following rule works fine
RewriteRule ^([a-z][a-z])/(.*)$ $2?lang=$1

But when the sef is turned on it goes to 404-category not found page

Anojan Sivarajah




msg:4451699
 8:04 am on May 10, 2012 (gmt 0)

so the url will be in the format of
www.example.com/en/corporate/news

but actually shows the contents from]
www.example.com/corporate/news/?lang=en

This rule is fine but it doesn't work with Joomla SEF turned on and i really need the sef to be on

lucy24




msg:4451758
 11:20 am on May 10, 2012 (gmt 0)

That "sef" isn't simply a button. It causes things to happen behind the scenes, probably by enabling a package of rewrites. So you need to find those rewrites and study them. Or throw out the default sef and do the whole thing yourself manually.

Fortunately, there are people hereabouts who know much more about the inner workings of joomla than I do ;) You just have to wait for the right time zone to roll around.

g1smd




msg:4451977
 9:01 pm on May 10, 2012 (gmt 0)

The order of the rules is important.

Your rewrites need to go ahead of the Joomla rewrites, but after all of the redirects.

The patterns in your rewrites need to match the URLs you are interested in and not match any of the URLs that Joomla should handle natively.

Anojan Sivarajah




msg:4452071
 2:35 am on May 11, 2012 (gmt 0)

how would i do that? joomla sef rewrites ain't on the .htaccess file. i tried to move my rule in the .htaccess file to different places but no luck

BillyS




msg:4452072
 2:55 am on May 11, 2012 (gmt 0)

Are you using Joomfish? lucy24 and g1smd are great at solving these problems. I've been using SEF urls in Mambo / Joomla since 2004. I don't think you've made it clear exactly what you're trying to do (sorry).

For example, do you want to take this URL:

http://www.example.com/corporate/news/?lang=fr

and redirect it to:

http://www.example.com/fr/corporate/news

OR

Do you want to take this URL:

http://www.example.com/corporate/news/?lang=fr

and make it look like:

http://www.example.com/fr/corporate/news

BillyS




msg:4452073
 2:56 am on May 11, 2012 (gmt 0)

how would i do that? joomla sef rewrites ain't on the .htaccess file. i tried to move my rule in the .htaccess file to different places but no luck

g1smd is referring to the order these rules appear in the .htaccess file. They need to come before this:
########## Begin - Joomla! core SEF Section

Do a search for g1smd optimized joomla and you'll have a better understanding of what he's saying. (Assuming g1smd is a male).

Anojan Sivarajah




msg:4452084
 3:37 am on May 11, 2012 (gmt 0)

I want to take this URL:

http://www.example.com/corporate/news/?lang=fr

and make it look like:

http://www.example.com/fr/corporate/news

@BillyS
My rewriterule is before the begin - joomla core sef

Anojan Sivarajah




msg:4452085
 3:39 am on May 11, 2012 (gmt 0)

Here is a copy of my .htaccess file

##
# @version$Id: htaccess.txt 21101 2011-04-07 15:47:33Z dextercowley $
# @packageJoomla
# @copyrightCopyright (C) 2005 - 2011 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 /
RewriteRule ^([a-z][a-z])/(.*)$ $2?lang=$1 [QSA,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 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.

g1smd




msg:4452091
 5:27 am on May 11, 2012 (gmt 0)

mod_rewrite cannot make a URL "look" like anything. It cannot change the URLs in the links on your pages.

For mod_rewrite to work, the first step is to change the links on your pages to refer to the right URLs. mod_rewrite does its thing only after that link is clicked.

RewriteBase /
RewriteRule ^([a-z][a-z])/(.*)$ $2?lang=$1 [QSA,L]


Delete the first line. It's the default.

Place a slash before $2 unless you want your server hacked. Make it /$2...

The meat of the problem is this. The part that matches (.*) is passed to $2. You need to know that whatever it says, there should be a resource at the exact same path and filename inside the server in order to fulfil that request... and that's where the rule properly fails. You don't have a physical folder and file called /corporate/news inside the server.

You're trying to rewrite a URL to another URL. mod_rewrite does not do that. The right hand side of the rule should point to the actual real internal server filepath that will deliver the content. This likely includes "index.php" or some such similar filename.

Are these URL requests supposed to be handled by the core Joomla index.php file or are they handled by an extra file you've written and installed?

I'd expect to see somthing like this:
RewriteRule ^([a-z][a-z])/(.*)$ /myindex.php?path=$2&lang=$1 [QSA,L]

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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved