Welcome to WebmasterWorld Guest from 54.197.171.28

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Duplicate Rewrite Rules In .htaccess File

I am having an issue concerning duplicate rewrite rules in the .htaccess

   
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
9:54 pm on Sep 3, 2013 (gmt 0)

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



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.
5:13 am on Sep 4, 2013 (gmt 0)

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



welcome to WebmasterWorld, Eric!


it would be safest to start your target urls with the root directory's leading slash.
6:27 am on Sep 4, 2013 (gmt 0)

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



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

Featured Threads

Hot Threads This Week

Hot Threads This Month