.htaccess rewrite problem

So I really don’t know or understand much with htaccess. I am trying to do a simple url rewrite for a blog type thing. I want to take a url like amecms.com/view-article.php?article=whatever-whatever and make it show like amecms.com/article/whatever-whatever. I can get it to rewrite technically I guess but I think because of the added article/ in the url the page is not figuring out the directory correctly and isn’t finding my css file and other files to include.

You can check out what I mean amecms.com/articles.php and choose a article. Here is the rewrite rule I have so far.

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteRule ^article/(.*)$ ./view-article.php?article=$1

Any help is appreciated.

Oh how I love searching an trying for hours and finally posting for help and then 2 seconds later find a solution. I ended up using a tag that tells files to use the path in the href of the tag for guidance. I set it to my main domain name and it all seems to work how I want.

<base href="http://www.example.com/" />

All other pages seem to work fine too. I don’t honestly know if this is the correct or best way to make it work, so I am very interested in what other methods to try.

That’s something on my figure out how to do list!

EDIT: Relevant documentation on .htaccess files here.

I never liked using .htaccess files. I feel as if I’m dirtying all of the directories with hard to maintain configuration instructions. I like using the tags within either the main httpd.conf or a separate .conf that is then loaded into the httpd.conf through include statements, though I haven’t used this to include separate .conf files yet in my own development setup yet.

More Info regarding Apache Includes.
Note: Above documentation is for Apache Version 2.4!

Sponsor our Newsletter | Privacy Policy | Terms of Service