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

    
Redirecting to static URL when dynamic URL is requested
Directing a GET query to a static URL
borisbaloney




msg:3673014
 1:49 pm on Jun 12, 2008 (gmt 0)

I've been able to get my dynamic pages disabling correctly under static URLs, and I'm trying to ensure these static URLs are used only (duplicate content issues etc).

I was hoping someone could point me in the right direction with what I have in my .htaccess file.

Based on jdMorgan's explanation of the rewrite [webmasterworld.com], I've got the following:

# Enable mod_rewrite, start rewrite engine
Options +FollowSymLinks
RewriteEngine on
#
# Internally rewrite search engine friendly static URL to dynamic filepath and query
RewriteRule ^(.*)view/(.*)/(.*)$ $1cgi-bin/view.pl?order=$2&orderdirection=$3

#
# Externally redirect client requests for old dynamic URLs to equivalent new static URLs
rewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /view\.pl\?order=([^&]+)&orderdirection=([^\ ]+)\ HTTP/
rewriteRule ^view\.pl$ http://www.example.com/view/%1/%2? [R=301,L]

These rules have www.example.com/view/DISK/ASC retrieving it's content from www.example.com/cgi-bin/view.pl?order=DISK&orderdirection=ASC correctly, but when the script is called directly it doesn't direct the user to the static page for the content.

Is there anything obvious that I've messed up with the .htaccess formatting?

I understand the "power" of regular expressions, but reading and writing .htaccess files feels like I'm on one of those code obsfucation contents...

My thanks in advanced to anyone providing assistance.

 

jdMorgan




msg:3673024
 2:07 pm on Jun 12, 2008 (gmt 0)

If "view.pl" is located in /cgi-bin, then you'll need to include "cgi-bin" in both patterns of your second rule.

Your first rule is using terribly-inefficient patterns. Using ".*" multiple times in one pattern leads to horrible performance, because of the number of "trial" passes that the regex parser has to make to resolve them. It can also lead to very strange and unexpected matches, because ".*" matches anything.

I'd suggest re-coding that first rule as:

RewriteRule ^(.*)view/([^/]+)/([^/]+)$ $1cgi-bin/view.pl?order=$2&orderdirection=$3

This is better, but still leaves that initial ambiguous ".*" in place. Unfortunately, I cannot tell what is intended there. Regardless of the intent, however, I would suggest making that pattern more specific. If it is intended to be a single-level subdirectory path, the "([^/]+/)" is appropriate. If that subdirectory path is optional, then "([^/]+/)?" is appropriate, and if any number of subdirectories are to be acceptted, then "(([^/]+/)*)" will work.

Jim

borisbaloney




msg:3673633
 2:17 am on Jun 13, 2008 (gmt 0)

Thanks Jim, that was the key. I appreciate your assistance.

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