Forum Moderators: phranque
i have a simple site that generates URLs like
Code:
[localhost...]
[localhost...]
.. so on.
i want to rewrite the above URLs on fly to something like
Code:
[localhost...]
[localhost...]
respectively,
I wrote .htaccess file with code,
Code:
RewriteEngine on
RewriteBase /url
RewriteRule ^productid([^.]+).*$ products.php?id=$1 [T=application/x-httpd-php]
my target is that when i browse site it should change the dynamic URLs to static on fly and rename them with .htm extension. Well, now the problem is that its not working, i mean nothing happens when i browse site, and it still shows me the dynamic URLs generated from database. i am confused whether my Apache is not working or this .htaccess code is invalid.
please help me to accompish this task
thanks in advance
To use 'friendly' URLs, do the following:
mod_rewrite takes action during the URL-to-filename translation phase of HTTP request processing, before any content-handlers are invoked and before any scripts are executed. It does not act on the content output by your server. Therefore, it cannot 'change the links on your pages' -- the ones that users click on and that search engines index. It can only change the file or script associated with a URL that is requested from your server.
Always remember that this is incoming URL-rewriting, not output content-filtering.
mod_rewrite will change an incoming requested URL matching the pattern on the left immediately following the RewriteRule directive to that given in the substitution URL on the far right side of the RewriteRule directive. So, a URL that matches the left-side pattern is rewritten or redirected to the filepath or URL specified on the right. Schematically:
RewriteRule old_URL_pattern -> new_substitution_filepath/URL [flags]
To make the job of changing your dynamic on-page URLs easier on a database-driven site, you can often make use of PHP preg_replace to change the links on-the-fly. So PHP is used to make your dynamic links static, people bookmark those static links and search engines list them in search results. Then when people or search engines request a static link from your site, mod_rewrite sends the request to your script in the dynamic form that it expects, the script generates a new page with static links on it, and the process starts over again.
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