简体   繁体   English

Apache mod_rewrite 更改文件扩展名

[英]Apache mod_rewrite to change file extension

I want to change all requests to a file with the extension.user.js to be made to a.php.我想将所有对扩展名为.user.js 的文件的请求更改为a.php。 I have this code:我有这个代码:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule /([^/]*)\.user\.js$ $1.php [R,NC]

</ifModule>

That unfortunately does not work.不幸的是,这不起作用。 I know mod_rewrite is loaded because, if I do this:我知道 mod_rewrite 已加载,因为如果我这样做:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule /([^/]*)\.user\.js$ $1.php [R,NC]
s
</ifModule>

It returns a status code of 500. So I believe my problem is in the regex.它返回状态码 500。所以我相信我的问题出在正则表达式中。
Example of what I want:我想要的示例:

GET /foo/bar/preetyuserscript.user.js

becomes变成

GET /foo/bar/preetyuserscript.php

I think this will work:我认为这会起作用:

RewriteRule ^(.*?)\.user\.js$ $1.php

If it doesn't and you continue to see 500 errors have a look in the error log.如果没有,并且您继续看到 500 个错误,请查看错误日志。 Always the first place to check out.永远是第一个退房的地方。

Correct RewriteRule should be:正确的 RewriteRule 应该是:

RewriteRule ^([^.]*)\.user\.js$ /$1.php [R,L,NC]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM