Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite

just starting

         

PeteM

7:53 pm on Feb 7, 2006 (gmt 0)

10+ Year Member



Hi,

I've read some tutorials now I'm trying to get some results.

I've coded the following in my .htaccess file.....

Options +FollowSymLinks
RewriteEngine on
RewriteRule x(.*)-(.*)\.htm$ /index.php?SearchIndex=$1&Title=$2

.....and my URL looks like this.....

[wwWebmasterWorldebsite.co.uk...]

Problem is nothing is happening i.e. the mod-rewrite is not altering the URL.

I checked my server settings and found

Loaded Modules: mod_evasive, mod_security, mod_auth_passthrough, mod_log_bytes, mod_php4, mod_frontpage, mod_ssl, mod_setenvif, mod_so, mod_expires, mod_auth, mod_access, mod_rewrite, mod_alias, mod_userdir, mod_actions, mod_imap, mod_asis, mod_cgi, mod_dir, mod_autoindex, mod_include, mod_status, mod_negotiation, mod_mime, mod_log_config, mod_env, http_core

I'm sure there's a simple answer. Please help!

Thanks, Pete

jdMorgan

2:48 am on Feb 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



and my URL looks like this:

http://example.com/index.php?SearchIndex=X#*$!&Title=Yyyy

I assume that that is the desired 'output' URL. What does your 'input' URL look like?

I suspect something else is wrong, URL-wise, procedurally, or with your expectations. But your rule would be more efficient with a couple of tweaks:


RewriteRule x([^-]+)-([^.]+)\.htm$ /index.php?SearchIndex=$1&Title=$2 [L]

The ".*" pattern is ambiguous, greedy, and slow, because it requires multiple 'trials' to find a match. The negative-match patterns above will match much more quickly and efficiently, because they are specific. The [L] flag says that if this rule matches, there is no need to process subsequent rules. Use it always, unless you have a specific reason not to.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

PeteM

8:25 am on Feb 8, 2006 (gmt 0)

10+ Year Member



Thanks Jim, I'll read the docs later.

My input looks like

http://www.example.com/index.php?SearchIndex=Aaaa&Title=Bccc 

and i'd like my output to look something like

http://www.example.com/Aaaa_Bccc.htm

Thanks, Pete

jdMorgan

2:01 pm on Feb 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In that case, I'm afraid you're going about this backwards. The tutorials in our Library cover this subject pretty well, but understand that rewriting takes place as a request arrives at your server, and before any content is served or any scripts are executed. It changes the relationship between a requested URL and the filename or path to the content which corresponds to that URL. It does not act as any kind of 'filter' that can change links on the pages that you have published.

Synopsis:

Put static links on your pages, then rewrite those static links, when requested, to the script needed to serve your content.

Having done that, you can add more code to redirect the old dynamic links to the new static links, to acclerate the removal of the old dynamic links from search results, to recover any PageRank/LinkPop from those old links, to prevent duplicate-content problems, and to 'clean up' your log files and stats.

Jim

PeteM

5:50 pm on Feb 8, 2006 (gmt 0)

10+ Year Member



Ahhhhhhhhhhhhhhh. Now I understand. Got it working already! School-boy error?

Thanks, as ever, Pete

tupots

5:26 pm on Feb 10, 2006 (gmt 0)

10+ Year Member



Thanks for all the info on the .htaccess file. 301 rewrites can be tricky and it's good to make a backup of the file before you fiddle with it. That way you can always revert back if something goes haywire.

In a few days I'm going to attempt to do a 301 as I'm managing a site with 2 domains that point to the same site (same account even with webserver). I can access the htaccess through GoLive and hope all goes well - these forums have been a big help in getting me familiar with the procedure.