homepage Welcome to WebmasterWorld Guest from 54.227.12.219
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Duplicate Rewrite Rules In .htaccess File
I am having an issue concerning duplicate rewrite rules in the .htaccess
UnconventionalPanda




msg:4607064
 1:53 pm on Sep 3, 2013 (gmt 0)

I am attempting to rewrite a certain page (example.com/php/otherPages.php?pageSlug=example) to example.com/example.html while still displaying the content found on the said page. However I already have similar rewrite rules in my .htaccess that are messing with how the rule works. My code is below so you can better see what I'm talking about.

RewriteRule ^([^/\.]+)\.html?$ php/statePage.php?region_slug=$1 [L]
RewriteRule ^([^/\.]+)-tree-services/([^/\.]+)\.html?$ php/cityPage.php?region_slug=$2&state_slug=$1 [L]
RewriteRule ^([^/\.]+)-tree-services/([^/\.]+)/([^/\.]+)\.html?$ php/vendorPage.php?slug=$3&region_slug=$2&state_slug=$1 [L]

RewriteRule ^([^/\.]+)-Sitemap\.xml?$ php/xmlState.php?region_name=$1 [L]

RewriteRule ^([^/\.]+)\.html?$ php/otherPages.php?pageSlug=$1 [L]


The top 4 rewrite rules work however the bottom one (the rule that is supposed to execute what is explained above) doesn't. When I take the bottom rule and place it at the top it works however, the rest of the code doesn't. I have determined that this is because ^([^/\.]+)\.html?$ is the same throughout the file. Is there any way to fix this or another code that I can put in that will function in the same way that I want it to function?

Thank you for any and all help,
Eric

 

lucy24




msg:4607142
 9:54 pm on Sep 3, 2013 (gmt 0)

Rule 5 appears to be identical to Rule 1, so it will never execute.

btw you don't need to escape literal periods inside grouping brackets. (Literal spaces, yes.) Leave a blank line after each rule. That's for your own sake; mod_rewrite doesn't care.

I am attempting to rewrite a certain page (example.com/php/otherPages.php?pageSlug=example) to example.com/example.html

No, you're not. Based on both the form of the rule and the content of the post, you're attempting to rewrite /example.html to /php/etcetera.

What's the intended difference between rules 1 and 5? Maybe you'd better explain in English what each one is intended to accomplish.

phranque




msg:4607164
 5:13 am on Sep 4, 2013 (gmt 0)

welcome to WebmasterWorld, Eric!


it would be safest to start your target urls with the root directory's leading slash.

lucy24




msg:4607169
 6:27 am on Sep 4, 2013 (gmt 0)

Follow-up: It's possible that you've misunderstood the relationship between target and pattern. The pattern, the part on the left, is what the user (whether human or robot) requests. Your server compares each request against the pattern; if there's a match, it does the stuff on the right. This applies in a general way to any Apache activity that involves evaluating some aspect of the request.

The two targets

/statePage.php?region_slug=blahblah

/otherPages.php?pageSlug=blahblah

each correspond to some URL that the user has requested. But the request can't simply be
([^/.]+)\.html
There has to be some way for the server to know if the person really wants statePage.php or otherPages.php. If there's no way to tell the URLs apart, you have to either list each group by name, or let a preliminary php script sort them out.

Oh, and: In a redirect, it might be appropriate to use the form
\.html?
with optional l, especially if you've got a lot of outside sites pointing to the wrong form of your URL. But in a rewrite you can only permit one form. Otherwise you'll have duplicate content in the most literal way (an html version and an htm version of every URL).

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