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

    
Help with a mod rewrite
nestman




msg:4541115
 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]

 

lucy24




msg:4541135
 11:37 pm on Jan 31, 2013 (gmt 0)

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.)

g1smd




msg:4541158
 1:04 am on Feb 1, 2013 (gmt 0)

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.

nestman




msg:4541163
 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]

lucy24




msg:4541174
 3:11 am on Feb 1, 2013 (gmt 0)

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.

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