Convert web.config file to .htaccess file
I have a web.config file that I have tried converting to .htaccess and it's not working as intended. I'd love some help figuring out where I went wrong.
web.config
<rewrite>
<rules>
<rule name="Redirect to https">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="Blocker" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{PATH_INFO}" pattern="^/version_" />
</conditions>
<action type="Redirect" url="https://www.example.com/404/" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="API Director">
<match url="(.*)" />
<conditions>
<add input="{PATH_INFO}" pattern="^/api/v1/" />
</conditions>
<action type="Rewrite" url="/controller.php" />
</rule>
<rule name="HoverCart App" stopProcessing="true">
<match url=".*" />
<conditions>
<!--<add input="{HTTP_HOST}" pattern="^(.*)(quiverstest.)" />-->
<add input="{PATH_INFO}" pattern="^/newrelic/" negate="true" />
</conditions>
<action type="Rewrite" url="app{R:0}" />
</rule>
</rules>
</rewrite>
.htaccess
RewriteRule (.*) https://{HTTP_HOST}{REQUEST_URI}
RewriteCond %{PATH_INFO} ^/version_
RewriteRule (.*) https://www.example.com/404/
RewriteCond %{PATH_INFO} ^/api/v1/
RewriteRule (.*) /controller.php
RewriteCond %{PATH_INFO} ^/newrelic/
RewriteRule .* app$0
specifically /api/v1 isn't working. Im getting a 404 when its trying to pull in https://localhost/api/v1/app/
to be honest I dont know much about either web.config or .htaccess, I'm trying to set up something on a mac that was initially made for windows machines.
EDIT
the most important rule that I need to rewrite is this one
<rule name="API Director">
<match url="(.*)" />
<conditions>
<add input="{PATH_INFO}" pattern="^/api/v1/" />
</conditions>
<action type="Rewrite" url="/controller.php" />
</rule>
this is the error that I get
The requested URL /api/v1/app/ was not found on this server.
Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.
php apache .htaccess iis web-config
add a comment |
I have a web.config file that I have tried converting to .htaccess and it's not working as intended. I'd love some help figuring out where I went wrong.
web.config
<rewrite>
<rules>
<rule name="Redirect to https">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="Blocker" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{PATH_INFO}" pattern="^/version_" />
</conditions>
<action type="Redirect" url="https://www.example.com/404/" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="API Director">
<match url="(.*)" />
<conditions>
<add input="{PATH_INFO}" pattern="^/api/v1/" />
</conditions>
<action type="Rewrite" url="/controller.php" />
</rule>
<rule name="HoverCart App" stopProcessing="true">
<match url=".*" />
<conditions>
<!--<add input="{HTTP_HOST}" pattern="^(.*)(quiverstest.)" />-->
<add input="{PATH_INFO}" pattern="^/newrelic/" negate="true" />
</conditions>
<action type="Rewrite" url="app{R:0}" />
</rule>
</rules>
</rewrite>
.htaccess
RewriteRule (.*) https://{HTTP_HOST}{REQUEST_URI}
RewriteCond %{PATH_INFO} ^/version_
RewriteRule (.*) https://www.example.com/404/
RewriteCond %{PATH_INFO} ^/api/v1/
RewriteRule (.*) /controller.php
RewriteCond %{PATH_INFO} ^/newrelic/
RewriteRule .* app$0
specifically /api/v1 isn't working. Im getting a 404 when its trying to pull in https://localhost/api/v1/app/
to be honest I dont know much about either web.config or .htaccess, I'm trying to set up something on a mac that was initially made for windows machines.
EDIT
the most important rule that I need to rewrite is this one
<rule name="API Director">
<match url="(.*)" />
<conditions>
<add input="{PATH_INFO}" pattern="^/api/v1/" />
</conditions>
<action type="Rewrite" url="/controller.php" />
</rule>
this is the error that I get
The requested URL /api/v1/app/ was not found on this server.
Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.
php apache .htaccess iis web-config
RewriteRule (.*) https://{HTTP_HOST}{REQUEST_URI}
I'm kinda surprised that doesn't result in a terminal loop tbh - unless http and https have different docroots (and therefore .htaccess rules).
– CD001
Nov 12 at 16:56
hmm like I said, I really have 0 experience with either web.config and .htaccess so Im not too sure:P but, It doesnt result in a terminal loop. and I don't think they have different docRoots either
– Gavyn Caldwell
Nov 12 at 17:07
Enable the rewritelog. All thoseRewriteCond %PATH_INFO
are redundant. Move the actual regex in place of the RewriteRule(.*)
for starters.
– mario
Nov 12 at 17:08
what would that look like? @mario
– Gavyn Caldwell
Nov 12 at 17:12
add a comment |
I have a web.config file that I have tried converting to .htaccess and it's not working as intended. I'd love some help figuring out where I went wrong.
web.config
<rewrite>
<rules>
<rule name="Redirect to https">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="Blocker" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{PATH_INFO}" pattern="^/version_" />
</conditions>
<action type="Redirect" url="https://www.example.com/404/" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="API Director">
<match url="(.*)" />
<conditions>
<add input="{PATH_INFO}" pattern="^/api/v1/" />
</conditions>
<action type="Rewrite" url="/controller.php" />
</rule>
<rule name="HoverCart App" stopProcessing="true">
<match url=".*" />
<conditions>
<!--<add input="{HTTP_HOST}" pattern="^(.*)(quiverstest.)" />-->
<add input="{PATH_INFO}" pattern="^/newrelic/" negate="true" />
</conditions>
<action type="Rewrite" url="app{R:0}" />
</rule>
</rules>
</rewrite>
.htaccess
RewriteRule (.*) https://{HTTP_HOST}{REQUEST_URI}
RewriteCond %{PATH_INFO} ^/version_
RewriteRule (.*) https://www.example.com/404/
RewriteCond %{PATH_INFO} ^/api/v1/
RewriteRule (.*) /controller.php
RewriteCond %{PATH_INFO} ^/newrelic/
RewriteRule .* app$0
specifically /api/v1 isn't working. Im getting a 404 when its trying to pull in https://localhost/api/v1/app/
to be honest I dont know much about either web.config or .htaccess, I'm trying to set up something on a mac that was initially made for windows machines.
EDIT
the most important rule that I need to rewrite is this one
<rule name="API Director">
<match url="(.*)" />
<conditions>
<add input="{PATH_INFO}" pattern="^/api/v1/" />
</conditions>
<action type="Rewrite" url="/controller.php" />
</rule>
this is the error that I get
The requested URL /api/v1/app/ was not found on this server.
Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.
php apache .htaccess iis web-config
I have a web.config file that I have tried converting to .htaccess and it's not working as intended. I'd love some help figuring out where I went wrong.
web.config
<rewrite>
<rules>
<rule name="Redirect to https">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="Blocker" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{PATH_INFO}" pattern="^/version_" />
</conditions>
<action type="Redirect" url="https://www.example.com/404/" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="API Director">
<match url="(.*)" />
<conditions>
<add input="{PATH_INFO}" pattern="^/api/v1/" />
</conditions>
<action type="Rewrite" url="/controller.php" />
</rule>
<rule name="HoverCart App" stopProcessing="true">
<match url=".*" />
<conditions>
<!--<add input="{HTTP_HOST}" pattern="^(.*)(quiverstest.)" />-->
<add input="{PATH_INFO}" pattern="^/newrelic/" negate="true" />
</conditions>
<action type="Rewrite" url="app{R:0}" />
</rule>
</rules>
</rewrite>
.htaccess
RewriteRule (.*) https://{HTTP_HOST}{REQUEST_URI}
RewriteCond %{PATH_INFO} ^/version_
RewriteRule (.*) https://www.example.com/404/
RewriteCond %{PATH_INFO} ^/api/v1/
RewriteRule (.*) /controller.php
RewriteCond %{PATH_INFO} ^/newrelic/
RewriteRule .* app$0
specifically /api/v1 isn't working. Im getting a 404 when its trying to pull in https://localhost/api/v1/app/
to be honest I dont know much about either web.config or .htaccess, I'm trying to set up something on a mac that was initially made for windows machines.
EDIT
the most important rule that I need to rewrite is this one
<rule name="API Director">
<match url="(.*)" />
<conditions>
<add input="{PATH_INFO}" pattern="^/api/v1/" />
</conditions>
<action type="Rewrite" url="/controller.php" />
</rule>
this is the error that I get
The requested URL /api/v1/app/ was not found on this server.
Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.
php apache .htaccess iis web-config
php apache .htaccess iis web-config
edited Nov 12 at 17:35
asked Nov 12 at 16:48
Gavyn Caldwell
326
326
RewriteRule (.*) https://{HTTP_HOST}{REQUEST_URI}
I'm kinda surprised that doesn't result in a terminal loop tbh - unless http and https have different docroots (and therefore .htaccess rules).
– CD001
Nov 12 at 16:56
hmm like I said, I really have 0 experience with either web.config and .htaccess so Im not too sure:P but, It doesnt result in a terminal loop. and I don't think they have different docRoots either
– Gavyn Caldwell
Nov 12 at 17:07
Enable the rewritelog. All thoseRewriteCond %PATH_INFO
are redundant. Move the actual regex in place of the RewriteRule(.*)
for starters.
– mario
Nov 12 at 17:08
what would that look like? @mario
– Gavyn Caldwell
Nov 12 at 17:12
add a comment |
RewriteRule (.*) https://{HTTP_HOST}{REQUEST_URI}
I'm kinda surprised that doesn't result in a terminal loop tbh - unless http and https have different docroots (and therefore .htaccess rules).
– CD001
Nov 12 at 16:56
hmm like I said, I really have 0 experience with either web.config and .htaccess so Im not too sure:P but, It doesnt result in a terminal loop. and I don't think they have different docRoots either
– Gavyn Caldwell
Nov 12 at 17:07
Enable the rewritelog. All thoseRewriteCond %PATH_INFO
are redundant. Move the actual regex in place of the RewriteRule(.*)
for starters.
– mario
Nov 12 at 17:08
what would that look like? @mario
– Gavyn Caldwell
Nov 12 at 17:12
RewriteRule (.*) https://{HTTP_HOST}{REQUEST_URI}
I'm kinda surprised that doesn't result in a terminal loop tbh - unless http and https have different docroots (and therefore .htaccess rules).– CD001
Nov 12 at 16:56
RewriteRule (.*) https://{HTTP_HOST}{REQUEST_URI}
I'm kinda surprised that doesn't result in a terminal loop tbh - unless http and https have different docroots (and therefore .htaccess rules).– CD001
Nov 12 at 16:56
hmm like I said, I really have 0 experience with either web.config and .htaccess so Im not too sure:P but, It doesnt result in a terminal loop. and I don't think they have different docRoots either
– Gavyn Caldwell
Nov 12 at 17:07
hmm like I said, I really have 0 experience with either web.config and .htaccess so Im not too sure:P but, It doesnt result in a terminal loop. and I don't think they have different docRoots either
– Gavyn Caldwell
Nov 12 at 17:07
Enable the rewritelog. All those
RewriteCond %PATH_INFO
are redundant. Move the actual regex in place of the RewriteRule (.*)
for starters.– mario
Nov 12 at 17:08
Enable the rewritelog. All those
RewriteCond %PATH_INFO
are redundant. Move the actual regex in place of the RewriteRule (.*)
for starters.– mario
Nov 12 at 17:08
what would that look like? @mario
– Gavyn Caldwell
Nov 12 at 17:12
what would that look like? @mario
– Gavyn Caldwell
Nov 12 at 17:12
add a comment |
1 Answer
1
active
oldest
votes
That's a rather crude autotranslation you got there.
Regex rules should rarely go into RewriteConds:
RewriteCond %{PATH_INFO} ^/api/v1/
RewriteRule (.*) /controller.php
Should each be just:
RewriteRule ^api/v1/ /controller.php
The leading
/
should be omitted (from any^/…
).
Environment references need
%
in Apache context:
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
↑ ↑
This one in particular needs a RewriteCond to only match for http:// requests.
Pretty sure these should be forward slashes:
RewriteRule .* app$0
↑ ↑
Keep the comments from the original web.config
Thank you! this brought me much closer I do however still get this errorThe requested URL /api/v1/app/ was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
– Gavyn Caldwell
Nov 12 at 18:44
How to debug Apache mod_rewrite
– mario
Nov 12 at 18:57
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53266644%2fconvert-web-config-file-to-htaccess-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
That's a rather crude autotranslation you got there.
Regex rules should rarely go into RewriteConds:
RewriteCond %{PATH_INFO} ^/api/v1/
RewriteRule (.*) /controller.php
Should each be just:
RewriteRule ^api/v1/ /controller.php
The leading
/
should be omitted (from any^/…
).
Environment references need
%
in Apache context:
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
↑ ↑
This one in particular needs a RewriteCond to only match for http:// requests.
Pretty sure these should be forward slashes:
RewriteRule .* app$0
↑ ↑
Keep the comments from the original web.config
Thank you! this brought me much closer I do however still get this errorThe requested URL /api/v1/app/ was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
– Gavyn Caldwell
Nov 12 at 18:44
How to debug Apache mod_rewrite
– mario
Nov 12 at 18:57
add a comment |
That's a rather crude autotranslation you got there.
Regex rules should rarely go into RewriteConds:
RewriteCond %{PATH_INFO} ^/api/v1/
RewriteRule (.*) /controller.php
Should each be just:
RewriteRule ^api/v1/ /controller.php
The leading
/
should be omitted (from any^/…
).
Environment references need
%
in Apache context:
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
↑ ↑
This one in particular needs a RewriteCond to only match for http:// requests.
Pretty sure these should be forward slashes:
RewriteRule .* app$0
↑ ↑
Keep the comments from the original web.config
Thank you! this brought me much closer I do however still get this errorThe requested URL /api/v1/app/ was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
– Gavyn Caldwell
Nov 12 at 18:44
How to debug Apache mod_rewrite
– mario
Nov 12 at 18:57
add a comment |
That's a rather crude autotranslation you got there.
Regex rules should rarely go into RewriteConds:
RewriteCond %{PATH_INFO} ^/api/v1/
RewriteRule (.*) /controller.php
Should each be just:
RewriteRule ^api/v1/ /controller.php
The leading
/
should be omitted (from any^/…
).
Environment references need
%
in Apache context:
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
↑ ↑
This one in particular needs a RewriteCond to only match for http:// requests.
Pretty sure these should be forward slashes:
RewriteRule .* app$0
↑ ↑
Keep the comments from the original web.config
That's a rather crude autotranslation you got there.
Regex rules should rarely go into RewriteConds:
RewriteCond %{PATH_INFO} ^/api/v1/
RewriteRule (.*) /controller.php
Should each be just:
RewriteRule ^api/v1/ /controller.php
The leading
/
should be omitted (from any^/…
).
Environment references need
%
in Apache context:
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
↑ ↑
This one in particular needs a RewriteCond to only match for http:// requests.
Pretty sure these should be forward slashes:
RewriteRule .* app$0
↑ ↑
Keep the comments from the original web.config
edited Nov 12 at 18:33
answered Nov 12 at 18:24
mario
124k17182253
124k17182253
Thank you! this brought me much closer I do however still get this errorThe requested URL /api/v1/app/ was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
– Gavyn Caldwell
Nov 12 at 18:44
How to debug Apache mod_rewrite
– mario
Nov 12 at 18:57
add a comment |
Thank you! this brought me much closer I do however still get this errorThe requested URL /api/v1/app/ was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
– Gavyn Caldwell
Nov 12 at 18:44
How to debug Apache mod_rewrite
– mario
Nov 12 at 18:57
Thank you! this brought me much closer I do however still get this error
The requested URL /api/v1/app/ was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
– Gavyn Caldwell
Nov 12 at 18:44
Thank you! this brought me much closer I do however still get this error
The requested URL /api/v1/app/ was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
– Gavyn Caldwell
Nov 12 at 18:44
How to debug Apache mod_rewrite
– mario
Nov 12 at 18:57
How to debug Apache mod_rewrite
– mario
Nov 12 at 18:57
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53266644%2fconvert-web-config-file-to-htaccess-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
RewriteRule (.*) https://{HTTP_HOST}{REQUEST_URI}
I'm kinda surprised that doesn't result in a terminal loop tbh - unless http and https have different docroots (and therefore .htaccess rules).– CD001
Nov 12 at 16:56
hmm like I said, I really have 0 experience with either web.config and .htaccess so Im not too sure:P but, It doesnt result in a terminal loop. and I don't think they have different docRoots either
– Gavyn Caldwell
Nov 12 at 17:07
Enable the rewritelog. All those
RewriteCond %PATH_INFO
are redundant. Move the actual regex in place of the RewriteRule(.*)
for starters.– mario
Nov 12 at 17:08
what would that look like? @mario
– Gavyn Caldwell
Nov 12 at 17:12