I want to show the URL

cat and subcat in the URLs may be present, but not always.

I have put this .htaccess file in designit folder:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]
RewriteRule ^portfolio/?$ portfolio.php[NC,QSA]
RewriteRule ^portfolio/([a-zA-Z0-9_-]+)/?$ portfolio.php?cat=$1[L,NC,QSA]

Now, It is showing

but it is not showing

I get "Internal Server Error.The server encountered an internal error or misconfiguration and was unable to complete your request."

What do I need to do to fix this?

  • what is the point of the rule RewriteRule ^portfolio/?$ portfolio.php[NC,QSA] ? If I do understand what you've done, it's already modified by the previous RewriteRule (note that the ? at the end of and URL is considered as the Query string and is not considerered a part of the URL (checkout how the QSA directive works to understand it here: httpd.apache.org/docs/current/mod/mod_rewrite.html)) Nov 14 '11 at 9:24
  • Another suggestion: here's what your RewriteRules mean: "if it's not a directory, and not a file, then whatever is it, add ".php" at the end then stop (L stands for "Last" in your rule [L,QSA]). So you will never apply your two last rules unless they are really files. But in your two last rules, it seems it doesn't look for URL that concern files... Thus I'm sorry, but my suggestion would be to spend more time on the rewrite rule page I've given you on my previous comment. It's not easy, I know, but it's how you design good sites! Nov 14 '11 at 9:29
  • @Oliver (1st comment), you're probably right, but consider that lot of web developers use RewriteRule in everyday job, even most of them don't know much about servers. On SO it's easier for them to find solution, because mostly they are not members of SF.
    – Wh1T3h4Ck5
    Nov 14 '11 at 9:32

Here's your solution:


should give


You only need one rewrite rule:

RewriteEngine On
RewriteRule /designit/portfolio/([a-z]+)/([a-z]+)$ /designit/portfolio.php?cat=$1&subcat=$2

Please note that:

  • cat and subcat should only be alpha caracters (you may change it to fit your needs)
  • you don't need to test whether it's a file or not, because "only alpha caracters = no extension = you're sure it's not a file that is requested" (unless you share files that have no extension, but it would be strange (to the least))
  • +1 looks like right solution
    – Wh1T3h4Ck5
    Nov 14 '11 at 9:18

Refer below URL: Might help you.


  • Thank you for your help.But i have already solved it.Now i am facing another problem.when there is a blank space in subcat name or in cat name then my code is not working.my current code is as follows:Options +FollowSymlinks RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-z0-9]+)$ $1.php [QSA] RewriteRule ^portfolio-([a-z0-9]+)$ portfolio.php?cat=$1 [QSA] RewriteRule ^portfolio-([a-z0-9]+)-([a-z0-9]+)$ portfolio.php?cat=$1&subcat=$2 [QSA] help me please
    – Anusri Roy Chowdhury
    Nov 14 '11 at 11:10
  • Try : ([a-z0-9-\s]+) The \s will take care of blank spaces.
    – Alfred
    Nov 14 '11 at 11:38

Put your more specific rule, the 2nd one, before general rule and it should work.


Try below:

RewriteEngine on
RewriteRule ^portfolio/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$   /disignit/portfolio.php?first-var=$1&second-var=$2  [NC]
  • I'm sorry but you definitely should avoid writing the whole host website (if you can). In this case you can, so, from my own pov, you'd better remove "http://some.com". Nov 14 '11 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.