Forum Moderators: phranque

Message Too Old, No Replies

Mod rewrite ignoring substitution

redirection working but not translated to the URL

         

rgouveia

12:06 pm on Feb 6, 2008 (gmt 0)

10+ Year Member



Hi

We are having problems with the new written URL.

A link to our rewritten URL:
http://www.example.com/1/title-page.htm

works fine, and display the correct page, but the rewritten URL is changed to the form:
http://www.example.com/content/index.php?action=detailfo&rec=1

Hereīs our htaccess configuration, thats itīs working fine in other servers.

---------------------------
Options -Indexes
Options +FollowSymLinks
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} .
Rewritecond %{HTTP_HOST} ^example\.com
Rewritecond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*)$ http://www.example.com/$1?%1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*).htm$ http://www.example.com/$1/index.php?action=$2&$3=$4&$5=$6&$7=$8&$9=$10 [L,QSA]
---------------------------

Thank you.

[edited by: jdMorgan at 2:31 pm (utc) on Feb. 6, 2008]
[edit reason] example.com [/edit]

jdMorgan

2:35 pm on Feb 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



  • Do not specify a full URL; Doing so forces an external redirect -- as documented.
  • There is a limit of nine back-references ($1-$9) per RewriteRule, as documented.
  • Do not use multiple ".*" subpatterns; Doing so is extremely inefficient, requiring many, many, back-off-and-retry attempts to determine a match. Use negative-match subpatterns to enable evaluation in a single left-to-right pass.
  • Escape literal "." characters within patterns.
  • The [QSA] flag is not required, unless you plan to request /a/b/c/d/e/f/g/h.htm with a query string attached.

    The closest you can get to a working single rule --with the given limit of 9 variables-- is:


    RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^.]+)\.htm$ /$1/index.php?action=$2&$3=$4&$5=$6&$7=$8 [QSA,L]

    You may use the [C] flag to construct chained rules to support more than 9 variables.

    Note also that in your first rule (the domain canonicalization redirect), it is unnecessary to take steps to 'carry forward' the query string -- It will pass through the RewriteRule unmodified by default. Therefore, your second RewriteCond is not needed, and you may remove "?%1" from the RewriteRule substitution URL.

    For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

    Jim

  • rgouveia

    10:00 am on Feb 8, 2008 (gmt 0)

    10+ Year Member



    Our problem was solved and we've optimized our code.

    Thanks for the support jd.