htaccess RewriteRule results in 404 responseWhy do I get a double trailing slash depending on where my RewriteRule is located?Additionally, a 404 Not Found.htaccess & Mod_RewriteHow to exclude a sub-folder from HTaccess RewriteRuleInstalling wordpress in sub-directory with .htaccess in root directory.htaccess https redirect best methodExecute a PHP File Without the .PHP Extension on IISNginx rewrite, from htaccess-filesFix ERR_TOO_MANY_REDIRECTS after adding trailing slash in URLmod_rewrites in nested .htaccess causing strange 404
A map of non-pathological topology?
Sci-fi novel: ark ship from Earth is sent into space to another planet, one man woken early from cryosleep paints a giant mural
Teaching a class likely meant to inflate the GPA of student athletes
Is this a bug in plotting step functions?
First sign that you should look for another job?
If I leave the US through an airport, do I have to return through the same airport?
Separate SPI data
Longest bridge/tunnel that can be cycled over/through?
How to trick the reader into thinking they're following a redshirt instead of the protagonist?
Fermat's statement about the ancients: How serious was he?
Why did Intel abandon unified CPU cache?
Proving that a Russian cryptographic standard is too structured
Russian word for a male zebra
Advantages of the Exponential Family: why should we study it and use it?
What would be the way to say "just saying" in German? (Not the literal translation)
How can I remove material from this wood beam?
Why am I getting a strange double quote (“) in Open Office instead of the ordinary one (")?
Is it possible to have 2 different but equal size real number sets that have the same mean and standard deviation?
What is the logic behind taxing money for property?
With Ubuntu 18.04, how can I have a hot corner that locks the computer?
How to publish items after pipeline is finished?
Next date with distinct digits
Does putting salt first make it easier for attacker to bruteforce the hash?
What differences exist between adamantine and adamantite in all editions of D&D?
htaccess RewriteRule results in 404 response
Why do I get a double trailing slash depending on where my RewriteRule is located?Additionally, a 404 Not Found.htaccess & Mod_RewriteHow to exclude a sub-folder from HTaccess RewriteRuleInstalling wordpress in sub-directory with .htaccess in root directory.htaccess https redirect best methodExecute a PHP File Without the .PHP Extension on IISNginx rewrite, from htaccess-filesFix ERR_TOO_MANY_REDIRECTS after adding trailing slash in URLmod_rewrites in nested .htaccess causing strange 404
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a website that is in the root folder. It has a .htaccess
with teh code below:
RewriteEngine on
RewriteRule ^(.*)/$ $1.php
When I open http://example.com/login/
I get a "404 Not Found" error but when I open http://example.com/login
without the trailing /
the URL opens without any problem.
I need .htaccess
code to set in the root directory to open PHP file like login.php
as /login/
or /login
(without trailing /
).
.htaccess mod-rewrite rewrite
add a comment |
I have a website that is in the root folder. It has a .htaccess
with teh code below:
RewriteEngine on
RewriteRule ^(.*)/$ $1.php
When I open http://example.com/login/
I get a "404 Not Found" error but when I open http://example.com/login
without the trailing /
the URL opens without any problem.
I need .htaccess
code to set in the root directory to open PHP file like login.php
as /login/
or /login
(without trailing /
).
.htaccess mod-rewrite rewrite
add a comment |
I have a website that is in the root folder. It has a .htaccess
with teh code below:
RewriteEngine on
RewriteRule ^(.*)/$ $1.php
When I open http://example.com/login/
I get a "404 Not Found" error but when I open http://example.com/login
without the trailing /
the URL opens without any problem.
I need .htaccess
code to set in the root directory to open PHP file like login.php
as /login/
or /login
(without trailing /
).
.htaccess mod-rewrite rewrite
I have a website that is in the root folder. It has a .htaccess
with teh code below:
RewriteEngine on
RewriteRule ^(.*)/$ $1.php
When I open http://example.com/login/
I get a "404 Not Found" error but when I open http://example.com/login
without the trailing /
the URL opens without any problem.
I need .htaccess
code to set in the root directory to open PHP file like login.php
as /login/
or /login
(without trailing /
).
.htaccess mod-rewrite rewrite
.htaccess mod-rewrite rewrite
edited May 24 at 21:57
DocRoot
20519
20519
asked Aug 19 '12 at 15:48
MahmoodMahmood
62
62
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Try ^([^/]+)/?$
and see if it works as expected.
After try this code RewriteEngine on RewriteRule ^([^/]+)/?$ $1.php i got 500 error
– Mahmood
Aug 19 '12 at 16:21
By simply making the trailing slash optional (and still having an all-encompassing capturing subpattern) you would expect this to create a rewrite loop (hence the 500 error). A request for/login/
would rewrite to/login.php
to/login.php.php
to/login.php.php.php
, etc.
– DocRoot
May 24 at 21:33
add a comment |
This behavior is typical of a conflict with MuiltiViews
. You should disable MultiViews at the top of your .htaccess
file:
Options -MultiViews
This explains why /login
without the trailing /
successfully serves the file - your RewriteRule
is entirely bypassed in this scenario.
With MultiViews enabled, when requesting /login/
, mod_negotiation mocks up a rewrite map and issues an internal subrequest for /login.php
before mod_rewrite gets to process the URL. The path-info (trailing /
) is added back, to become /login.php/
. This is passed back for further processing and matches your overly-generic (^(.*)/$
) RewriteRule
pattern, resulting in an internal rewrite to /login.php.php/
etc. Depending on your config, this could result in a 403 (as it can result in a malformed request), or a 404 (as you appear to be seeing).
Disabling MultiViews alone (as mentioned above) would solve this problem. However, you should also consider making your RewriteRule
pattern more restictive. For example, to avoid matching URLs that already contain a dot (ie. have a file extension):
RewriteRule ^([^.]+)/$ $1.php [L]
Simply making the regex more restrictive may even "fix" the error. However, it would be MultiViews making the internal subrequest, not mod_rewrite (your rule would simply be bypassed).
as
/login/
or/login
(with or without the trailing/
)
To allow the rule to work with either /login/
or /login
(ie. with or without the trailing slash) you would need to make the trailing slash optional, ie. /?
. But you would also need to either make the preceding pattern non-greedy or include the slash in the negated character class in order to avoid capturing the trailing slash in the backreference.
For example, either:
RewriteRule ^([^.]+?)/?$ $1.php [L]
Or,
RewriteRule ^([^./]+)/?$ $1.php [L]
But the second rule would only work with URLs that contain a single path segment, whereas the first would work with a URL of the form /foo/bar/login
.
In Summary
Options -MultiViews
RewriteEngine On
RewriteRule ^([^.]+?)/?$ $1.php [L]
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "2"
;
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%2fserverfault.com%2fquestions%2f419092%2fhtaccess-rewriterule-results-in-404-response%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try ^([^/]+)/?$
and see if it works as expected.
After try this code RewriteEngine on RewriteRule ^([^/]+)/?$ $1.php i got 500 error
– Mahmood
Aug 19 '12 at 16:21
By simply making the trailing slash optional (and still having an all-encompassing capturing subpattern) you would expect this to create a rewrite loop (hence the 500 error). A request for/login/
would rewrite to/login.php
to/login.php.php
to/login.php.php.php
, etc.
– DocRoot
May 24 at 21:33
add a comment |
Try ^([^/]+)/?$
and see if it works as expected.
After try this code RewriteEngine on RewriteRule ^([^/]+)/?$ $1.php i got 500 error
– Mahmood
Aug 19 '12 at 16:21
By simply making the trailing slash optional (and still having an all-encompassing capturing subpattern) you would expect this to create a rewrite loop (hence the 500 error). A request for/login/
would rewrite to/login.php
to/login.php.php
to/login.php.php.php
, etc.
– DocRoot
May 24 at 21:33
add a comment |
Try ^([^/]+)/?$
and see if it works as expected.
Try ^([^/]+)/?$
and see if it works as expected.
edited Aug 19 '12 at 18:15
HopelessN00b
48.7k25117194
48.7k25117194
answered Aug 19 '12 at 16:16
MoakMoak
2442627
2442627
After try this code RewriteEngine on RewriteRule ^([^/]+)/?$ $1.php i got 500 error
– Mahmood
Aug 19 '12 at 16:21
By simply making the trailing slash optional (and still having an all-encompassing capturing subpattern) you would expect this to create a rewrite loop (hence the 500 error). A request for/login/
would rewrite to/login.php
to/login.php.php
to/login.php.php.php
, etc.
– DocRoot
May 24 at 21:33
add a comment |
After try this code RewriteEngine on RewriteRule ^([^/]+)/?$ $1.php i got 500 error
– Mahmood
Aug 19 '12 at 16:21
By simply making the trailing slash optional (and still having an all-encompassing capturing subpattern) you would expect this to create a rewrite loop (hence the 500 error). A request for/login/
would rewrite to/login.php
to/login.php.php
to/login.php.php.php
, etc.
– DocRoot
May 24 at 21:33
After try this code RewriteEngine on RewriteRule ^([^/]+)/?$ $1.php i got 500 error
– Mahmood
Aug 19 '12 at 16:21
After try this code RewriteEngine on RewriteRule ^([^/]+)/?$ $1.php i got 500 error
– Mahmood
Aug 19 '12 at 16:21
By simply making the trailing slash optional (and still having an all-encompassing capturing subpattern) you would expect this to create a rewrite loop (hence the 500 error). A request for
/login/
would rewrite to /login.php
to /login.php.php
to /login.php.php.php
, etc.– DocRoot
May 24 at 21:33
By simply making the trailing slash optional (and still having an all-encompassing capturing subpattern) you would expect this to create a rewrite loop (hence the 500 error). A request for
/login/
would rewrite to /login.php
to /login.php.php
to /login.php.php.php
, etc.– DocRoot
May 24 at 21:33
add a comment |
This behavior is typical of a conflict with MuiltiViews
. You should disable MultiViews at the top of your .htaccess
file:
Options -MultiViews
This explains why /login
without the trailing /
successfully serves the file - your RewriteRule
is entirely bypassed in this scenario.
With MultiViews enabled, when requesting /login/
, mod_negotiation mocks up a rewrite map and issues an internal subrequest for /login.php
before mod_rewrite gets to process the URL. The path-info (trailing /
) is added back, to become /login.php/
. This is passed back for further processing and matches your overly-generic (^(.*)/$
) RewriteRule
pattern, resulting in an internal rewrite to /login.php.php/
etc. Depending on your config, this could result in a 403 (as it can result in a malformed request), or a 404 (as you appear to be seeing).
Disabling MultiViews alone (as mentioned above) would solve this problem. However, you should also consider making your RewriteRule
pattern more restictive. For example, to avoid matching URLs that already contain a dot (ie. have a file extension):
RewriteRule ^([^.]+)/$ $1.php [L]
Simply making the regex more restrictive may even "fix" the error. However, it would be MultiViews making the internal subrequest, not mod_rewrite (your rule would simply be bypassed).
as
/login/
or/login
(with or without the trailing/
)
To allow the rule to work with either /login/
or /login
(ie. with or without the trailing slash) you would need to make the trailing slash optional, ie. /?
. But you would also need to either make the preceding pattern non-greedy or include the slash in the negated character class in order to avoid capturing the trailing slash in the backreference.
For example, either:
RewriteRule ^([^.]+?)/?$ $1.php [L]
Or,
RewriteRule ^([^./]+)/?$ $1.php [L]
But the second rule would only work with URLs that contain a single path segment, whereas the first would work with a URL of the form /foo/bar/login
.
In Summary
Options -MultiViews
RewriteEngine On
RewriteRule ^([^.]+?)/?$ $1.php [L]
add a comment |
This behavior is typical of a conflict with MuiltiViews
. You should disable MultiViews at the top of your .htaccess
file:
Options -MultiViews
This explains why /login
without the trailing /
successfully serves the file - your RewriteRule
is entirely bypassed in this scenario.
With MultiViews enabled, when requesting /login/
, mod_negotiation mocks up a rewrite map and issues an internal subrequest for /login.php
before mod_rewrite gets to process the URL. The path-info (trailing /
) is added back, to become /login.php/
. This is passed back for further processing and matches your overly-generic (^(.*)/$
) RewriteRule
pattern, resulting in an internal rewrite to /login.php.php/
etc. Depending on your config, this could result in a 403 (as it can result in a malformed request), or a 404 (as you appear to be seeing).
Disabling MultiViews alone (as mentioned above) would solve this problem. However, you should also consider making your RewriteRule
pattern more restictive. For example, to avoid matching URLs that already contain a dot (ie. have a file extension):
RewriteRule ^([^.]+)/$ $1.php [L]
Simply making the regex more restrictive may even "fix" the error. However, it would be MultiViews making the internal subrequest, not mod_rewrite (your rule would simply be bypassed).
as
/login/
or/login
(with or without the trailing/
)
To allow the rule to work with either /login/
or /login
(ie. with or without the trailing slash) you would need to make the trailing slash optional, ie. /?
. But you would also need to either make the preceding pattern non-greedy or include the slash in the negated character class in order to avoid capturing the trailing slash in the backreference.
For example, either:
RewriteRule ^([^.]+?)/?$ $1.php [L]
Or,
RewriteRule ^([^./]+)/?$ $1.php [L]
But the second rule would only work with URLs that contain a single path segment, whereas the first would work with a URL of the form /foo/bar/login
.
In Summary
Options -MultiViews
RewriteEngine On
RewriteRule ^([^.]+?)/?$ $1.php [L]
add a comment |
This behavior is typical of a conflict with MuiltiViews
. You should disable MultiViews at the top of your .htaccess
file:
Options -MultiViews
This explains why /login
without the trailing /
successfully serves the file - your RewriteRule
is entirely bypassed in this scenario.
With MultiViews enabled, when requesting /login/
, mod_negotiation mocks up a rewrite map and issues an internal subrequest for /login.php
before mod_rewrite gets to process the URL. The path-info (trailing /
) is added back, to become /login.php/
. This is passed back for further processing and matches your overly-generic (^(.*)/$
) RewriteRule
pattern, resulting in an internal rewrite to /login.php.php/
etc. Depending on your config, this could result in a 403 (as it can result in a malformed request), or a 404 (as you appear to be seeing).
Disabling MultiViews alone (as mentioned above) would solve this problem. However, you should also consider making your RewriteRule
pattern more restictive. For example, to avoid matching URLs that already contain a dot (ie. have a file extension):
RewriteRule ^([^.]+)/$ $1.php [L]
Simply making the regex more restrictive may even "fix" the error. However, it would be MultiViews making the internal subrequest, not mod_rewrite (your rule would simply be bypassed).
as
/login/
or/login
(with or without the trailing/
)
To allow the rule to work with either /login/
or /login
(ie. with or without the trailing slash) you would need to make the trailing slash optional, ie. /?
. But you would also need to either make the preceding pattern non-greedy or include the slash in the negated character class in order to avoid capturing the trailing slash in the backreference.
For example, either:
RewriteRule ^([^.]+?)/?$ $1.php [L]
Or,
RewriteRule ^([^./]+)/?$ $1.php [L]
But the second rule would only work with URLs that contain a single path segment, whereas the first would work with a URL of the form /foo/bar/login
.
In Summary
Options -MultiViews
RewriteEngine On
RewriteRule ^([^.]+?)/?$ $1.php [L]
This behavior is typical of a conflict with MuiltiViews
. You should disable MultiViews at the top of your .htaccess
file:
Options -MultiViews
This explains why /login
without the trailing /
successfully serves the file - your RewriteRule
is entirely bypassed in this scenario.
With MultiViews enabled, when requesting /login/
, mod_negotiation mocks up a rewrite map and issues an internal subrequest for /login.php
before mod_rewrite gets to process the URL. The path-info (trailing /
) is added back, to become /login.php/
. This is passed back for further processing and matches your overly-generic (^(.*)/$
) RewriteRule
pattern, resulting in an internal rewrite to /login.php.php/
etc. Depending on your config, this could result in a 403 (as it can result in a malformed request), or a 404 (as you appear to be seeing).
Disabling MultiViews alone (as mentioned above) would solve this problem. However, you should also consider making your RewriteRule
pattern more restictive. For example, to avoid matching URLs that already contain a dot (ie. have a file extension):
RewriteRule ^([^.]+)/$ $1.php [L]
Simply making the regex more restrictive may even "fix" the error. However, it would be MultiViews making the internal subrequest, not mod_rewrite (your rule would simply be bypassed).
as
/login/
or/login
(with or without the trailing/
)
To allow the rule to work with either /login/
or /login
(ie. with or without the trailing slash) you would need to make the trailing slash optional, ie. /?
. But you would also need to either make the preceding pattern non-greedy or include the slash in the negated character class in order to avoid capturing the trailing slash in the backreference.
For example, either:
RewriteRule ^([^.]+?)/?$ $1.php [L]
Or,
RewriteRule ^([^./]+)/?$ $1.php [L]
But the second rule would only work with URLs that contain a single path segment, whereas the first would work with a URL of the form /foo/bar/login
.
In Summary
Options -MultiViews
RewriteEngine On
RewriteRule ^([^.]+?)/?$ $1.php [L]
edited May 24 at 21:22
answered May 24 at 21:07
DocRootDocRoot
20519
20519
add a comment |
add a comment |
Thanks for contributing an answer to Server Fault!
- 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%2fserverfault.com%2fquestions%2f419092%2fhtaccess-rewriterule-results-in-404-response%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