Nikhil Mourya Nikhil Mourya - 1 year ago 80
Apache Configuration Question

After using .htaccess RewriteRule page not opening properly

I am trying to convert my dynamic PHP link to a clear link; for that I used RewriteRule. But the work seems to be not done properly

I am trying to convert;



RewriteRule ^product/([0-9]+)$ product.php?prodct_id=$1 [NC,L]

After this the page does not load properly. But if I remove
, the page loads perfectly

RewriteRule ^([0-9]+)$ product.php?prodct_id=$1 [NC,L];

Answer Source

Your page won't load fully because you are referring to your CSS and JavaScript resources relative to the current location. You need to change this to refer to the resources relative to the root of the site. For example, change this:

<link rel="stylesheet" type="text/css" href="css/slider-pro.min.css" media="screen"/>

to this:

<link rel="stylesheet" type="text/css" href="/css/slider-pro.min.css" media="screen"/>

Note the leading slash before css/slider.... You need to do this for all your CSS, jQuery and image resources. Alternatively, you can save time by adding the following to your <head> node:

<base href="/">

Or, even better:

<base href="">

Additionally, I recommend you do the same with your mod_rewrite rule:

RewriteRule ^product/([0-9]+)$ /product.php?product_id=$1 [NC,L]

Lastly, I recommend you ensure Multiviews is not enabled, by adding this line to the top of the file:

Options -Multiviews
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download