Welcome to WebmasterWorld Guest from 54.145.235.72

Forum Moderators: Ocean10000 & incrediBILL & phranque

Help with a mod rewrite

   
10:27 pm on Jan 31, 2013 (gmt 0)



The 2nd mod rewrite is working fine. I just need to figure out what I'm doing wrong for the 1st one. When they click on the old format, I want the URL in the web browser to show the new format of example.com/most-recent

Thanks!

1. # When user is clicking on the old format
RewriteRule ^aromatherapy.php?t=1$ most-recent [L]


2. # When user is clicking on the new format
RewriteRule ^most-recent$ aromatherapy.php?t=1 [L]
11:37 pm on Jan 31, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



Woo hoo, an easy one.

Neither of your rules is a redirect. They are both rewrites: User thinks they are at point A, while your server is secretly serving up content from B.

In order for the URL (the contents of the address bar) to change, you have to redirect:

RewriteRule {input here} http://www.example.com/{output here} [R=301,L]

Full protocol and domain name AND R=301 flag. AND keep the [L]. (This is counter-intuitive but essential.)
1:04 am on Feb 1, 2013 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



In addition to both of your rules being rewrites when you need to alter the first one to be a redirect (still using RewriteRule syntax of course), the other reason the first rule doesn't work is that your pattern is trying to match path and parameters.

RewriteRule patterns can match only the path part of the URL request. You need a preceding RewriteCond that looks at the QUERY_STRING or in this case at THE_REQUEST to be sure that the user requested a URL with an appended query string.

Don't forget to escape the literal period in the RegEx pattern.

Use example.com in this forum to supress URL auto-linking.
1:41 am on Feb 1, 2013 (gmt 0)



Am I getting closer?

# Most Recent postings
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^example.php?t=1 http://www.example.com/recent [R=301,L]
RewriteRule ^example.php?t=1$ recent [L]
3:11 am on Feb 1, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



Further away, I think.

What has the HTTP_HOST got to do with anything? Unless you have subdomains, you should have only one rule that looks at the HTTP_HOST -- and this isn't it.

You missed the part of g1's post where he explained that mod_rewrite can't see parameters. In the body of a Rule,

example.php?t=1


will be interpreted as

"www.example.com/example{any single character}ph{optional p}t=1"

I do not think you will get many requests for this filename.

You need a preceding RewriteCond that looks at the QUERY_STRING or in this case at THE_REQUEST


The line for THE_REQUEST is because you only want to redirect people who explicitly asked for the long ugly form of the name-- not people who asked for the short pretty form and have been secretly rewritten to the longer uglier form.

Here [webmasterworld.com] is one version of the boilerplate. Third post (second reply) in thread, the part in the "quote" block.
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month