Forum Moderators: phranque

Message Too Old, No Replies

URL mod rewrite help needed

modrewrite help

         

diger

4:04 pm on Aug 28, 2008 (gmt 0)

10+ Year Member



Hello everyone,

Greetings.

I know only little about modrewrite. And this is not working.

Rewrite Rule ^view/music\.html$ index.php?loadpage=./lib/view.php&category=$1 [L]

Actual url: www.site.com/view/music.html

I don't know why this is not working. Can someone help me with this. I'll greatly appreciate any help.

Thanks

jdMorgan

4:43 pm on Aug 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please tell us what the "category" is supposed to be -- show how the example URL is supposed to 'map' to the index.php variables.

Also, do you intend this one rule to support multiple 'categories'? If so, then we will need examples of the URLs and the proper script parameters for those URLs.

Jim

diger

8:39 am on Aug 29, 2008 (gmt 0)

10+ Year Member



Yeah the script is intended for multiple categories. Above scripts works without rewrite rule. Like

index.php?loadpage=./lib/view.php&category=music ->for music category
index.php?loadpage=./lib/view.php&category=finance -> for finance category

What the script do is list the articles of particular categories. These works without modrewrite. With modrewrite rule I only need to pass category variable to the script through .htaccess.

jdMorgan

12:48 pm on Aug 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In that case, use a pattern to detect <whatever>.html, and create a back-reference, putting <whatever> into variable $1 so you can use it in the substitution URL-path on the right. For example:

Rewrite Rule ^view/([^.]+)\.html$ index.php?loadpage=./lib/view.php&category=$1 [L]

Jim

diger

9:54 am on Aug 30, 2008 (gmt 0)

10+ Year Member



I guess it's working although the page template is not loading properly.

Thanks Jim

jdMorgan

12:47 pm on Aug 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Likely because you've used page-relative links in that template. Change the image/media, CSS, and external JavaScript links in that template from page-relative (e.g <img src="images/logo.gif"> ) to server-relative ( e.g. <img src="/images/logo.gif"> ) to fix this.

Alternatively, you can detect and rewrite the URLs to image, media, CSS, and JS includes to correct them, but this creates duplicate content.

Remember that it is the client (the browser) which resolves relative URLs. The client now thinks your page is located in the subdirectory /view, and all page-relative URLs will be resolved to that directory. You can check your server error and access logs to confirm this.

Jim