Php .htaccess:仅使用值重写规则不起作用

Php .htaccess:仅使用值重写规则不起作用,php,apache,.htaccess,mod-rewrite,url-rewriting,Php,Apache,.htaccess,Mod Rewrite,Url Rewriting,我已经做了很多研究来解决这个问题,但我仍然不明白为什么它不起作用。最初,我重新编写了我的URL以添加.html,但我想改变这一点,并使它们保持简单,没有任何后缀 以下是原始链接的示例 http://www.howwe.biz/artist?a=eddy-kenzo 我使用下面的规则更改上面的链接并添加后缀.html RewriteRule^([^/]*)\.html$/artist?a=$1[L] 结果是:http://www.howwe.biz/eddy-kenzo.html 我想重写像这样的

我已经做了很多研究来解决这个问题,但我仍然不明白为什么它不起作用。最初,我重新编写了我的URL以添加
.html
,但我想改变这一点,并使它们保持简单,没有任何后缀

以下是原始链接的示例

http://www.howwe.biz/artist?a=eddy-kenzo

我使用下面的规则更改上面的链接并添加后缀.html

RewriteRule^([^/]*)\.html$/artist?a=$1[L]

结果是:
http://www.howwe.biz/eddy-kenzo.html

我想重写像这样的原始链接

http://www.howwe.biz/eddy-kenzo
我尝试使用
RewriteRule^([^/]*)$/artist?a=$1[L]
来实现这一点,但我遇到了一个可怕的服务器错误

内部服务器错误服务器遇到内部错误或配置错误,无法完成您的请求

请与服务器管理员联系,webmaster@howwe.biz并告知他们错误发生的时间,以及您可能采取的任何可能导致错误的措施

有关此错误的详细信息,请参阅服务器错误日志。此外,尝试使用ErrorDocument处理请求时遇到500内部服务器错误`

url中的eddy kenzo是值。奇怪的是,如果我添加了名称,在本例中是a,它就可以工作了。见下文:

重写规则^a/([^/]*)$/artist?a=$1[L]
http://www.howwe.biz/a/bebe-cool
但我需要这样的
http://www.howwe.biz/bebe-cool

我做错了什么。非常感谢你的帮助

对不起,如果这是tl;博士

这应该可以:

RewriteEngine on

#1redirect "/artist?a=foo" to "/foo"
RewriteCond %{THE_REQUEST} /artist\?a=([^\s]+) [NC]
RewriteRule ^ /%1? [NC,L,R]

#skip the rule if the request is for dir
RewriteCond %{REQUEST_FILENAME} !-d

 #skip the rule if the request is for file
 RewriteCond %{REQUEST_FILENAME} !-f
 #rewrite anyother request  to "/artist?a=" 
 RewriteRule ^([^/]+)/?$ /artist?a=$1 [NC,L]
你的规则

RewriteRule^([^/]*)$/artist?a=$1[L]
失败,因为它正在无条件地重写对目标url的任何请求,目标url与模式匹配,并重写为自身。您的规则将在以下条件下工作:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)$ /artist?a=$1 [L] 
这应该起作用:

RewriteEngine on

#1redirect "/artist?a=foo" to "/foo"
RewriteCond %{THE_REQUEST} /artist\?a=([^\s]+) [NC]
RewriteRule ^ /%1? [NC,L,R]

#skip the rule if the request is for dir
RewriteCond %{REQUEST_FILENAME} !-d

 #skip the rule if the request is for file
 RewriteCond %{REQUEST_FILENAME} !-f
 #rewrite anyother request  to "/artist?a=" 
 RewriteRule ^([^/]+)/?$ /artist?a=$1 [NC,L]
你的规则

RewriteRule^([^/]*)$/artist?a=$1[L]
失败,因为它正在无条件地重写对目标url的任何请求,目标url与模式匹配,并重写为自身。您的规则将在以下条件下工作:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)$ /artist?a=$1 [L] 
试试这个:

RewriteRule \/(.*)? /artist?a=$1
它从最后一个/后面到最后一个,将所有内容添加到$1。

尝试以下方法:

RewriteRule \/(.*)? /artist?a=$1

它从最后一个/到最后一个,把所有的东西都拿走,加上1美元。

非常感谢你@Starkeen。。。我不需要在你的代码中修改任何东西,它工作得非常完美。这个问题我已经有好几个月了,现在已经解决了!再次感谢!非常感谢你@Starkeen。。。我不需要在你的代码中修改任何东西,它工作得非常完美。这个问题我已经有好几个月了,现在已经解决了!再次感谢!