March 22, 2012

clean url not working with in a sub folder

Question by user1263260

I am developing a php web site. Here I have implemented clean URL using .htaccess file. I have successfully worked with clean URL but when I have created a sub folder named admin within the root folder htaccess is not working. So I have created another .htacess file inside the admin folder. See my code within the admin .htaccess

Options +FollowSymlinks

RewriteEngine on

RewriteRule ^(.*).html$ $1.php [nc]
RewriteRule product/id/(.*)/ product.php?id=$1
RewriteRule product/id/(.*) product.php?id=$1   
RewriteRule ^(.*).htm$ $1.php [nc]

RewriteRule login/f/(.*)/ login.html?f=$1
RewriteRule login/f/(.*) login.html?f=$1    

I have attempted to log in the admin section, I have logged and my page redirected to the login page

header("location:login/f/".$fail);

URL rewriting is working but my page results in a wrong manner i.e. Images and css are not affected my redirected page

Why this happened?

On is it possible to use only one .htacess file, while will work in both the admin side and front end
Does any one help me Please
Thanks

Answer by Starx

This is the problem with the links which can find the proper resource. I am pretty sure, you are using relative links to the files like ../styles/page.css.

You have to assign the links of the CSSs, Scripts and Images in such a way that rewritten URL, do not have any effects.

The easiest way to solve this without indulging in any other complication is give direct links to files.

Example:

<link rel="stylesheet" href="http://mydomain.com/styles/page.css" />

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!