我正在尝试使用名称作为 url,例如 stackoverflow。我有一个 godaddy linux 主机,并且正在使用 .htaccess 来控制 mod_rewrite url。
我正在尝试获得以下信息:
- /about => about.php
- /schools/add => add-school.php
- /api/questions/ask => /questions.php?action=ask
- /api/questions/158 => /questions.php?action=get&id=158
- /api/questions/144/points => /questions.php?action=get-points&id=144
这是我到目前为止所拥有的,但它不起作用:
## Mod rewrite manual: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
<IfModule mod_rewrite.c>
RewriteEngine On
# try the corresponding php file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([A-Za-z0-9_-]+) $1.php [qsa]
# special cases
RewriteRule ^schools\/add$ add-school.php
# API
RewriteRule ^api\/questions\/ask$ "api.php?action=ask" [qsa]
RewriteRule ^api\/questions\/(\d+)$ "api.php?action=get&id=$1" [qsa]
RewriteRule ^api\/questions\/(\d+)\/points$ "api.php?action=get-points&id=$1" [qsa]
</IfModule>