Forum Moderators: phranque

Message Too Old, No Replies

queries through mod_rewrite

queries url rewrite

         

froth

3:43 pm on Jan 23, 2006 (gmt 0)



I've been working a lot with dynamic content in phpbb, with values passed through queries (eg: script.php?variablea=556&variableb=97&variablec=2) but I've come across a situation where queries can't be used - dynamically generated images. For the bbcode img tag to work, the url to the image has to end in .jpg or .png et cetera, but in the above example the url ends with a 2!

My idea is to make a folder for the script (called scriptfolder for example) and have an htaccess file in the folder to do the url rewrites. so to call the script, you could go to:

[thesite.com...]

and the htaccess would redirect to:

[thesite.com...]

I don't know if it's possible to have the script be in the same folder as the redirect htaccess, nor do I have any idea of what the htaccess file should look like; the only stuff i've done with httpd and htaccess is custom error pages, directory indexes, and password protection. I hate to ask this, but can someone write me the htaccess file, or at least give me an idea of what the syntax for the regex (is that what rewritecond uses?) looks like? I hope I gave an accurate description of my problem.

Regards,
Brian

jdMorgan

6:29 pm on Jan 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Brian,

Welcome to WebmasterWorld!

We expressly discourage the writing of code on demand here; Please understand that the demand would far outstrip the ability of our small number of contributors to keep up. However, we will certainly support your effort to get started.

See the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com] for background information and examples, and also try searching this site for examples using the keywords "mod_rewrite," "rewriterule," "query string," etc.

Be aware that mod_rewrite works in the URL-to-filename translation phase of the Apache API, before any content is served and before any scripts are invoked. Therefore, it is likely that you will want to rewrite your search-friendly URLs to the form required by your script. You can place an .htaccess file in any HTTP- accessible directory on your site, and all rules will be applied hierarchically, with rules in subfolders overriding rules in their parent folders (in a standard Apache configuration).

Jim

extras

8:27 pm on Jan 23, 2006 (gmt 0)

10+ Year Member



What you want is often called as "Short URL" or "SEO friendly URL".
You will find many many examples if you search.

I don't think it's a good idea to use slash as delimiters, though.
Using underscore or hyphen in better, IMO.