Forum Moderators: phranque
I tried re-writing a dynamic URL successfully into static version but have two URLs working on the site now -
*ww.domain.com/properties_search.php?cat_id=1&type_id=1
& its static version
*ww.domain.com/1/1.htm.
Both these pages resolve to same page but I want the dynamic URL to be completly removed the site or re-directed to the new static version. Am I missing something in my re-write rule?
Thanks for your help..
The only way to do what your are asking simply, is to remove the links to the dynamic URL's from the site and replace them with the static version.
The more complicated version is to use %{THE_REQUEST}. If you are set on using Apache for this, plan on spending some time getting your rules and conditions to work. Depending on the number of URL's and variables present in those URL's, this technique can range from complicated to VERY complicated.
You can find more information on %{THE_REQUEST} and the regular expressions you will need to make things work in the forum charter. Just follow the links to the Apache documentation and the Regular Expression tutorial.
Hope this helps.
Justin
Added: If it is only one or two URL's %{THE_REQUEST} might be a effective option. If it is more than that, see above and decide which is better for your situation.
I have about about 200 odd dynamic URLs and identifying and changing each of them manually on site's internal pages would be a tedious job.
Is is a good idea to use 301 permanent re-direction from all dynamic URLs to its respective static verion? This way we will only have one static version for each URL.
Thanks for your help..
Shabir
PS: If I live the URLs as such will it be considered as two different URLs by engines and possible risk for duplicate page (/ URL) penalty.
is a good idea to use 301 permanent re-direction from all dynamic URLs to its respective static verion?
The only way to redirect a page that you still need to serve content from is by using %{THE_REQUEST}. There is no other way without causing an infinite loop or completely denying access to the page.
Depending on the URL's, variables, and pages involved, learning and implementing this may take more time than changing 200 links by hand.
Please, post an eaxmple of some of the URL's you will need to rewrite, but still serve information from, and include how standardized the formatting is.
Justin
Without more details on *how* your 300 URLs differ, it's hard to discuss. If there is something common about the URL or the query string in *all* of them, then you may be able to reduce the problem to a manageable number of rules.
Here is a demonstration of the code (using your posted example, plus an addition) to rewrite static to dynamic, and redirect dynamic to ststic without looping:
RewriteEngine on
# externally redirect dynamic to static [b]only[/b] for direct HTTP requests
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /properties_search\.php\?cat_id=([^&]+)&type_id=[^\ ]+])\ HTTP/
RewriteRule ^properties_search\.php$ http://%{HTTP_HOST}/%1/%2\.htm [R=301,L]
# internally rewrite static to dynamic
RewriteRule ^([^/]+)/([^.]+)\.htm$ /properties_search.php?cat_id=$1&type_id=$2 [L]
GET /properties_search.php?cat_id=<cat-value>&type_id=<type-value> HTTP/1.1
The redirect will be invoked if the client (browser or robot) requests the dynamic URL directly, but it will not be invoked on internal requests that result from the static-to-dynamic rewrite.
Jim
example.com/properties_search.php?cat_id=1&type_id=1
example.com/Properties/listing_detail.php?listing_id=99
example.com/News/marketresearch.php?nr_category_id=2
example.com/Properties/listing_detail.php?listing_id=140
Thanks..
Shabir
[edited by: jdMorgan at 9:58 pm (utc) on June 9, 2005]
[edit reason] Examplified. [/edit]