开发者

Apache mod_rewrite to change file extension

开发者 https://www.devze.com 2023-03-03 12:07 出处:网络
I want to change all requests to a file with the extension .user.js to be made to a .php. I have this code:

I want to change all requests to a file with the extension .user.js to be made to a .php. I have this code:

<IfModule mod_rewrite.c>
RewriteEngine on
Rewr开发者_C百科iteRule /([^/]*)\.user\.js$ $1.php [R,NC]

</ifModule>

That unfortunately does not work. I know mod_rewrite is loaded because, if I do this:

<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.

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. Always the first place to check out.


Correct RewriteRule should be:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号