Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite problem

re-writing works but do not show up on mouseover

         

shabir

8:40 pm on Jun 9, 2005 (gmt 0)

10+ Year Member



Hello..

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

shabir

8:45 pm on Jun 9, 2005 (gmt 0)

10+ Year Member



Here is the rule..

# mod_rewrite option
RewriteEngine on
RewriteRule ^([^/]+)/([^.]+)\.htm$ /properties_search.php?cat_id=$1&type_id=$2 [L]
#RewriteRule ^properties_search/([^/\.]+)/([^/\.]+)?$ properties_search.php?cat_id=$1&type_id=$2 [QSA, L]

jd01

8:49 pm on Jun 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi shabir,

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.

shabir

9:09 pm on Jun 9, 2005 (gmt 0)

10+ Year Member



Jd01 - thanks for your help. Looks like mod-rewrite is not going to be an easy task for me ;-)

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.

jd01

9:20 pm on Jun 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi shabir,

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

jdMorgan

9:25 pm on Jun 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can't use a Redirect (mod_alias) directive or a "normal" mod_rewrite redirect to remove your dynamic URLs. Otherwise, you will have one directive that that rewrites static to dynamic, and another that redirects dynamic to static, and the result will be an infinite loop of rewrite/redirection.

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]

For your reference in figuring out the regular expressions used in the redirect rule, %{THE_REQUEST} looks like this:
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

shabir

9:34 pm on Jun 9, 2005 (gmt 0)

10+ Year Member



Following are the dynamic URL patterns I would like to get rid of:

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]

shabir

9:41 pm on Jun 9, 2005 (gmt 0)

10+ Year Member



Thanks Jim, this is I think what I was looking for. Let me test this and get back to you with results..but looks like its gonna work smoothly for me now..

Shabir