Forum Moderators: phranque

Message Too Old, No Replies

Rewriting dynamic urls to static urls

         

Mohamed

6:05 pm on Feb 28, 2006 (gmt 0)

10+ Year Member



I have small problem which is I want convert dynamic urls to static urls and I am using this code, but it looks like the code is not working.

I want convert url from
www.example.com/artist.php?artist=John Smith
to
www.example.com/JohnSmith/


RewriteCond %{QUERY_STRING} ^artist\=([^&]+)$
RewriteRule ^$ /artist/%1-%2.html [R=301,L]

please help me!

[edited by: jdMorgan at 2:49 am (utc) on Mar. 1, 2006]
[edit reason] Reformatted using [ code ]. [/edit]

jdMorgan

2:48 am on Mar 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Mohamed,

Your code does not agree with your description of your goal. The code will only work for the index file. That is, the pattern "^$" will reject any local URL-path that is non-blank.

Actually, I suspect the problem is deeper. If you wish to use static, search-engine-friendly URLs on your site, then the following procedure should be used:

  • Replace all dynamic links on your pages with static links. This can be done using PHP preg_replace. These static links will then be clicked-on by users, and indexed by search engines.

  • Place code in your .htaccess file to convert those static links, when requested by users or search engine robots, back to the dynamic form needed to invoke your script(s).

    mod_rewrite is not an output filter. It operates in the URL-to-filename translation phase early in the request-handling process. It is used to modify URLs requested from your server before any content-handlers are invoked and before any scripts are executed. It cannot change the URLs displayed on your pages.

    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

  •