Pretty URL + CSS + Command-pattern + Controller (my combination doesn't work)

41 views Asked by At

I wish to have these pretty urls:

  • Overview of all categories: localhost/category
  • Form to make new category: localhost/category/new
  • Form to edit category: localhost/category/edit/4

Since I'm working with the Command pattern in my Controller I have these actions in my processRequest in my Controller I have these ugly urls:

  • localhost/index.php?action=categoryOverview
  • localhost/index.php?action=categoryNew
  • localhost/index.php?action=categoryNew&id=4

I'm trying this with .htaccess

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^([a-zA-Z]+)/([0-9]*) index.php?action=$1&id=$2

But this doesn't work + my CSS is not loading. I tried these:

<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="/css/bootstrap.css">
<link rel="stylesheet" href="css/bootstrap.css/">
<link rel="stylesheet" href="/css/bootstrap.css/">

Could you please help me how

  1. these pretty urls are done correctly?
  2. to have the css appear?
1

There are 1 answers

3
codeneuss On

Try to use the Conditions:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

instead of

RewriteCond %{REQUEST_FILENAME} !-f

So apache will try to find directories (-d) and symbolic links (-l) before passing the url to the controller.