Forum Moderators: phranque

Message Too Old, No Replies

help me in url rewrite

having problem in url rewrite.

         

youngpetals

10:49 am on Jul 29, 2006 (gmt 0)

10+ Year Member



i have some problem in my site. i add below code to .htaccess file
RewriteEngine On

RewriteRule ^(.*)/(.*)$ [sub.domain.com...] [NC]

this is subdomainurl/subfolder/file

now everything works fine. but the problem is the products images are not display in pages. all pages images are display correct. like logo, bullets etc. these images are in "images" folder and product images are in "productimg" folder.

there is form on the page and under that form product images are not display.
i send the path for images like this:- /folder/images/spacer.gif (these display fine)
product images path like this:- /folder/productimg/pro1.jpg

please tell me whats the problem or i have to make changes in product_details.php file. did i have to change the links there. is there any way that all links and forms works without changing the product details page.

Thanks in advance.

jdMorgan

4:09 pm on Jul 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You RewriteRule will rewrite *any URL* which is in the form "/subfolder(s)/file" to product_detail.php -- including your image requests.

Remember that ".*" matches anything -- including aditional slashes and subdirectory levels. Using multiple "." subpatterns in a pattern is also particularly inefficient.

I'd suggest that you make your RewriteRule pattern much more specific, or use a RewriteCond to exclude image paths from being rewritten.

I cannot say which is better, because I do not know how your site is structured. You'll need to decide the best way to examine the URL and decide whether or not it should be rewritten to your product_detail.php script. Then create a regular-expressions pattern to implement that.

Jim

youngpetals

6:11 am on Jul 30, 2006 (gmt 0)

10+ Year Member



can you give me some more details. how i make the code in product_details.php or .htaccess rewritecond.

the site structure is below.
mysite (http://www.mysite.com)
¦
¦-Folder (this is use as sub domain. [folder.mysite.com...] )
--¦
--¦-subfolder(this is folder of sub domain. [folder.mysite.com...]
----¦-.htaccess
----¦-product_details.php
----¦-images (this is images folder)
----¦-css (this css folder)
----¦-productimg (this is product images folder)

can you help me to make conditions and rules in .htaccess files and how i set path in product_details.php for product images.
is path like this
./images/imagename.jpg
./productimg/productimg.jpg
or
like this
/folder/images/imagename.jpg
/folder/productimg/productimg.jpg

please help me to sort out this problem.

Thanks in advance.

jdMorgan

1:49 pm on Jul 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



/folder/images/imagename.jpg would be the preferred way, simply because it is always taken as relative to the document root, so it it simply 'easier to think about' while working on the code.

First, let's try disabling the rule for image and css subfolders, while making the rule more specific and efficient:


RewriteCond $1 !^(images¦css¦productimg)$
RewriteRule ^([^/]+)/(.+)$ http://sub.example.com/folder/product_detail.php?pid=$1&pname=$2 [NC,L]

Important: Change the broken pipe "¦" characters above to solid pipes before attempting to use this code; Posting on this forum modifies the pipe character.

If your script can accept a 'blank' pname, then change the "(.+)" in the RewriteRule pattern to "(.*)"

Jim

[edited by: jdMorgan at 1:50 pm (utc) on July 30, 2006]