ConfigureWEB Posted October 7, 2011 Share Posted October 7, 2011 Hi, I have been reading about URL rewriting and mod_rewrite for a while but it seems I cannot make it work as I want. Here is my website I am working on: http://www.configureweb.com/ On this site I have different type of pages such as page.php, tutorial.php, post.php and category.php. Here is how the URLs are at the moment: http://www.configureweb.com/page.php?page=about http://www.configureweb.com/tutorial.php?tutorial=html-tutorial http://www.configureweb.com/post.php?post=sample-post http://www.configureweb.com/category.php?category=hosting-and-domains and here is how I want them to be: http://www.configureweb.com/page/about http://www.configureweb.com/tutorial/html-tutorial http://www.configureweb.com/post/sample-post http://www.configureweb.com/category/hosting-and-domains I tried something like the following code for pages: RewriteRule ^page/([A-Za-z0-9-]+)/?$ page.php?page=$1 [L] <a href="page/about">About</a> It redirects to the correct page but the stylesheet is not active and links on that page become like this: www.configureweb.com/page/page/about/ What am I doing wrong? Quote Link to comment Share on other sites More sharing options...
cags Posted October 7, 2011 Share Posted October 7, 2011 <a href="page/about">About</a> This is a relative path, assets requested by the browser will interpret this as relative to the current url. Since your rewrite makes it look like the file is one folder deep it's looking in the wrong place for the assets, you need to either use a full absolute URL or make them relative to root. In your case slapping a forward slash on the front of that should fix it. Quote Link to comment Share on other sites More sharing options...
requinix Posted October 7, 2011 Share Posted October 7, 2011 Also, there's one RewriteRule that'll cover all four examples, since they're all in the form /X/Y => X.php?X=Y: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}/$1.php -f RewriteRule ^([a-z]+)/(.*) $1.php?$1=$2 [L] That'll cover any future cases that are also in the form above. But it can create false positives; if that's a problem then change the Rule to RewriteRule ^(page|tutorial|post|category)/(.*) $1.php?$1=$2 [L] (which means that the third Cond isn't needed anymore) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.