.htaccess文件无法在服务器上运行

时间:2015-01-08 08:32:51

标签: php .htaccess

我有这样的网址

www.subdomain.mydomain.com/mydir/admin/index.php?page=dashboard

我希望拥有一个像这样的用户友好网址

www.subdomain.mydomain.com/mydir/admin/dashboard

我如何实现这一目标?我正在尝试使用下面提到的代码。我在这里做错了什么?

Options -MultiViews

# URL rewriting module activation
RewriteEngine on
RewriteCond %{REQUEST_METHOD} !^(TRACE|TRACK|GET|POST|HEAD)$
RewriteRule .* - [F]
RewriteBase /
Options +FollowSymLinks


RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?page=$1 [L]

有关类似情况,请参阅this question

1 个答案:

答案 0 :(得分:0)

试试这个.htaccess:

Options +FollowSymLinks -MultiViews   
RewriteEngine on

# use appropriate rewrite base
RewriteBase /mydir/admin/

RewriteCond %{REQUEST_METHOD} !^(TRACE|TRACK|GET|POST|HEAD)$
RewriteRule ^ - [F]

RewriteCond %{THE_REQUEST} /index\.php\?page=([\w-]+) [NC]
RewriteRule ^ %1?  [L,R]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ index.php?page=$1 [L,QSA]