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

    
Apache 301 redirects (for Joomla) question
apache 301 redirect wildcard Joomla SEF
You can call me Al




msg:4255992
 12:49 am on Jan 21, 2011 (gmt 0)

Hi,

First time posting here so hopefully i picked the correct forum for this.

Basically I have a Joomla site that I need a 301 redirect for, but try as I might I can't seem to get the correct syntax (or maybe it is the order I have wrong?)

I have an article which is found at

http : // www.mydomainnamehere.com.au/publications


However, some of my 'read more' links within 'articles appearing within modules' the SEF URL is not being correctly generated and appears relative to the current viewed article. (I know this is the real issue I need to solve but in the meantime I want to apply a 301 redirect)

So the incorrect link appears as

http : // www.mydomainnamehere.com.au/component/content/article/..current section name here.../79-publications

As the current section name changes based on where you are in the site I am ending up with loads of different URI's that all go to the same article.

So I simply want to redirect any URI REQUEST that ends in

/79-publications

to

http : // www.mydomainnamehere.com.au/publications

but i have tried many variations and none seem to be having any affect. So, hoping someone here can explain what I am doing wrong

Here is my 'best effort' code:


First I have my canonical rules (i have edited out the real domain so that it doesn't get indexed on this page).
This works fine.


RewriteEngine On

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


Then the bit that Joomla sticks in whi9ch I havent edited. This works well too:


########## 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



Then I tried this, but it didnt have any affect -

RewriteRule ^79-publications http : // www.mydomainnamehere.com.au/publications/ [R=301,L]


So then I tried this with the condition and the wild card, but again, no affect at all...

RewriteCond %{REQUEST_URI} \79-publications$
RewriteRule ^(.*)$ http : // www.mydomainnamehere.com.au/publications/? [R=301,L]


I also tried sticking

RewriteEngine On

in again just before my rule because I thought the ,L in the Joomla rules meant 'last redirect rule'. But again, no affect at all.

Sorry its a long post - just wanted to be clear about what I am trying to do, and what I had already attempted before posting for help..

Thanks in advance to anyone willing to help me out here.
cheers
Al

ps - i have added spaces to http : // in this post so it displays it.

 

g1smd




msg:4256059
 8:34 am on Jan 21, 2011 (gmt 0)

Your new code should go before all of the existing code. Is that where you placed it?

RewriteRule ^79-publications http://www.example.com.au/publications/ [R=301,L]

RewriteEngine On will be the very first thing, of course.
You can call me Al




msg:4257101
 11:25 pm on Jan 23, 2011 (gmt 0)

Hi,
I had it in this order:

1. ReWriteEngine On
2. canonical redirect to www version
3. joomla core SEF rules
4. my own redirect (that doesn't do anything!)

Have tried moving my own redirect to number 2 but still no affect.
I thought my redirect would need to come after the Joomla SEF rule - seeing as the URL I am trying to redirect is a Joomla SEF created one?

So just to confirm is the syntax
^79-publications
correct for saying "any URI ending in '79-publications'"?


RewriteRule ^79-publications http : // www.mydomainnamehere.com.au/publications/ [R=301,L]


A second problem I have noticed is that although the canonical redirect works it just always redirects the the main index.php domain URL of my site, rather than just inserting 'www' into teh requested URL if you see what i mean?

Thanks for you reply anyway. Any further ideas as to what i am doing wrong?

Al

g1smd




msg:4257111
 11:47 pm on Jan 23, 2011 (gmt 0)

So just to confirm is the syntax
^79-publications
correct for saying "any URI ending in '79-publications'"?

No. That's for anything that ^BEGINS with.

The syntax for "ends with" uses the $ symbol.

The page redirects must be listed before the non-www to www redirects. All redirects must be listed before any of the rewrites.

A rewrite does not "make" a new URL. A rewrite responds to an incoming URL request, and does so after a link has been clicked. The rewrite fetches the content from a different location in the server to that suggested by whatever the URL actually said.

A rewrite does not change the links on the pages. You have to change them yourself, or edit the PHP script which produces those links.

You can call me Al




msg:4257125
 12:34 am on Jan 24, 2011 (gmt 0)

So I have the wrong rule anyway!
Thank you heaps for all your help. Just brilliant to be able to learn this way!
So, I know the redirect rule wont change any links that are being generated in my pages, but when this one I cant fix just now is clicked thats when i want the redirect as a workaround.

So if i go for

79-publications$

Does the dollar at the end signify that this is the end of the URI request string? Do I not need anything in front of the 79? I thought I would need some kind of wild card like maybe

(^*)79-publications$ ..... the redirect URL...


Al

g1smd




msg:4257133
 12:57 am on Jan 24, 2011 (gmt 0)

You need something before it, only if you are going to capture that "something" in a backreference and re-use it; otherwise ends with blah$ is just fine.

You can call me Al




msg:4257138
 1:58 am on Jan 24, 2011 (gmt 0)

OK still not working!
The site is

www.revolutionlearning.com.au

Can you tell me this -

is placing
Redirect 301
at the start of the line the same as starting with
RewriteRule
then ending with
[R=301]
?


I basically just want to add a redirect rule which redirects any URL like this


[revolutionlearning.com.au...]

to this

[revolutionlearning.com.au...]


Is this possible?
Al

jdMorgan




msg:4257641
 12:34 am on Jan 25, 2011 (gmt 0)

Do not mix the use of mod_alias Redirect and RedirectMatch directives with mod_rewrite RewritRule directives. At best, this makes the order of execution unpredictable, and at worst, it results in incorrect execution and in the exposure of internal filepaths as URLs.

I basically just want to add a redirect rule which redirects any URL-path like this

/WHERE/THISBIT/CAN-BE/ANYTHING/79-publications
to a URL like this
http://example.com/publications

Is this possible?

Yes, and it can even be done quite efficiently as well:

RewriteRule ^([^/]+/)*79-publications$ http://www.example.com/publications [R=301,L]

The first bit of regex just says, "match as many directory-levels as you like" and allows the URL-path to be matched in a single left-to right pass.

It is marginally faster than the "79-publications$" pattern without a start-anchor because it identifies the "boundaries" following slashes where "79-publications" should be matched, and it also might prevent an unexpected match on a request for "/<something-anything>/1879-publications" as well.

Jim

g1smd




msg:4269761
 1:05 pm on Feb 20, 2011 (gmt 0)

There's a new Joomla .htaccess file currently being proposed. If you care to try it out, the code is at: [joomlacode.org...] and here:

##
# @version$Id$
# @packageJoomla
# @copyrightCopyright (C) 2005 - 2010 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).*script.*(\>|%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]
#
## End - Rewrite rules to block out some common exploits.

##
# 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}]
#
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|raw))$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.

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