URL重写给出500内部错误

时间:2013-12-26 20:35:05

标签: php .htaccess url-rewriting

我正在尝试执行网址重写,但却给了我500内部服务器错误

我有一个index.php文件,可以使用我称之为cmd的参数,因此网址应如下所示:

http://localhost/some_folder/index.php?cmd=some_parameter

我想要实现的目的是允许用户只输入以下任何内容:

http://localhost/some_folder/some_parameter

OR

http://localhost/some_folder/index/some_parameter

这是我的.htaccess文件:

RewriteEngine On    # Turn on the rewriting engine
RewriteRule    ^index.php/?$    index.php?cmd=shifts    [NC,L]

我也尝试过:

Options +FollowSymLinks
RewriteEngine on

RewriteRule /cmd/(.*)/ index.php?cmd=$1

我不知道我在这里做错了什么!

2 个答案:

答案 0 :(得分:1)

  

我发现此错误无效命令'RewriteEngine',可能拼写错误或由服务器配置中未包含的模块定义

您需要加载mod_rewrite。有关如何修复的详细信息,请参阅this answer

答案 1 :(得分:0)

经过大量的互联网搜索,特别是stackoverflow,我找到了一个解决方案(不是我想要的,但它现在正在工作,直到我找到另一个更适合我的需求。

这是我目前正在使用的.htaccess(实际上我使用2个文件,因为每个文件夹/子文件夹都有不同的参数):

Options +FollowSymLinks
RewriteEngine on
RewriteBase /rootFolder # In the sub-folder I type /rootFolder/subFolder
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule /cmd/(.*)/ index.php?R=$1 # In the sub-folder I type index.php?cmd=$1

现在我使用网址http://localhost/rootFolder/index/R/xxx-1234http://localhost/rootFolder/admin/index/cmd/xxx

进行访问

我需要做的是删除网址的index部分。

相关问题