Thursday 15 July 2010

php - .htaccess and mod_rewrite - can't get it to work -


I am trying to use names as URL, like stackoverflow I am a godaddy linux hosting and mod_rewrite url I am using .htaccess to control.

I am trying to get the following:

  • About / = & gt; About.php
  • / schools / plus = & gt; Add-school.php
  • / API / Question / Ask = & gt; /questions.php?action=ask
  • / API / question / 158 = & gt; /questions.php?action=get&id=158
  • / API / Question / 144 / Issue = & gt; /questions.php?action=get-points&id=144

    This is what I have done so far and it is not working:

      ## mod manual rewrite: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html & lt; IfModule mod_rewrite.c & gt; #RewriteEngine Try the same php file RewriteCond% {REQUEST_FILENAME}! -d RewriteCond% {REQUEST_FILENAME}! -f RewriteRule (Asking RewriteRule ^ [API-ZA-Z0-9_-] +) $ 1.php [QSA] # Special cases RewriteRule ^ schools / $ add-school.php # API RewriteRule ^ $ "Api.php? Action = ask" [QSA] RewriteRule ^ API / question \ / (\ d +) $ "api.php? Action = get & amp; id = $ 1" [QSA] RewriteRule ^ API \ / Question \ / (\ d +) \ / $ numeral "api.php action = get-points & amp; id = $ 1" [QSA]    

    There are some mistakes in your code:

    1. The rewrite order is very important. You should always order the most typical ones from the most common person. Remember that the general rules can match the pattern of specific rules and override those special cases.
    2. Always mark the personal end of the rule with L (last).
    3. To do .php you need to make sure that the php file actually exists

      with those suggestions here Your revised code:.

        option + follow link - multi view & lt; IfModule mod_rewrite.c & gt; Turn on #RedriteEngine on redriite # # Special case rewrite rule / add /? $ / Add-school.poP [L, NC] # API Rewriterable ^ API / Question / Inquiry / $ / APIPP [L, QSA, NC] RewriteRule ^ API / Question / (d +) / Issue /? $ /api.php?action=get-points&id=$1 [L, QSA, NC] RewriteRule ^ API / Question / (d +) /? $ /api.php?action=get&id=$1 [L, QSA, NC] #This php file tries, so it exists RewriteCond% {REQUEST_FILENAME}! -d RewriteCond% {REQUEST_FILENAME}! -f RewriteCond% {DOCUMENT_ROOT} / $ 1.php -f Rewrite Rules ^ (. +?) /? $ $ 1.php [L] & lt; / IfModule & gt;    

No comments:

Post a Comment