Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

links change depending on page they appear on

2:18 pm on Jun 8, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:May 23, 2005
votes: 0

I moved my site to an open source cms last night and have been having trouble with my .htaccess. The last problem I am aware of, and that I can't seem to solve, is that 'listings' change their url depending on which page they are linked from. For example 'listing-house-london-12' should always be www.example.com/listing-house-london-12.html. But when I hardcode a search onto a page like example.com/property/houses.html the link in the search results changes to /property/listing-house-london-12.html

Please see below the main part of the .htaccess. Is there something obvious that might need changing? Thanks in advance!

<IfModule mod_php4.c>
php_value session.use_trans_sid 0

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.(php¦html?)\ HTTP/
RewriteRule ^([^/]+/)*index\.(php¦html?)$ http://www.example.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301.L]
RewriteRule listing-(.*?)-([0-9]*).html index.php?action=listingview&listingID=$2 [L]
RewriteRule page-(.*?)-([0-9]*).html index.php?action=page_display&PageID=$2 [L]
RewriteRule searchresults.html index.php?action=searchresults [L]
RewriteRule agents.html index.php?action=view_users [L]
RewriteRule view_favorites.html index.php?action=view_favorites [L]
RewriteRule calculator.html index.php?action=calculator&popup=yes [L]
RewriteRule saved_searches.html index.php?action=view_saved_searches [L]
RewriteRule listing_image_([0-9]*).html index.php?action=view_listing_image&image_id=$1 [L]
RewriteRule logout.html index.php?action=logout [L]
RewriteRule member_signup.html index.php?action=signup&type=member [L]
RewriteRule agent_signup.html index.php?action=signup&type=agent [L]
RewriteRule member_login.html index.php?action=member_login [L]
RewriteRule edit_profile_([0-9]*).html index.php?action=edit_profile&user_id=$1 [L]
RewriteRule agent-([^-]*)-([0-9]*).html index.php?action=view_user&user=$2 [L]

4:43 pm on June 8, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0

Your rules are ambiguous, since they do not use start anchors, but that is not the likely problem. Rather, it seems that your expectations about what mod_rewrite does, and when it does it are not correct.

mod_rewrite acts *after* a user clicks on one of your links, sending an HTTP request to your server. Mod_rewrite receives this request, and can do one of several things. The most common actions are to internally rewrite the request to a different file path that what would be expected if the rewrite was not present, or to generate an external redirect to tell the browser to ask for the requested resource again, using a different URL.

Mod_rewrite cannot change the links that appear on your CMS-generated pages -- only your CMS can do that.

You'll need to modify your CMS to produce the correct URLs, and then mod_rewrite will rewrite them, when they are received from the client, to your "index.php" script.

For more information on the client-server transaction, and when and how mod_rewrite comes into play, see this thread, "Changing Dynamic URLs to Static URLs [webmasterworld.com]."

Additional information is available in our Forum Charter, and in the Apache forum Library -- See links at top of this page.