RewriteCond ignored in httpd.conf
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
Put simply this works in htaccess:
RewriteEngine on
RewriteCond %SCRIPT_FILENAME !-f
RewriteCond %SCRIPT_FILENAME !-d
RewriteRule ^([^/]+)/?$ https://example.net?u=$1 [L,NC,R=301]
But when I move it to httpd.conf it does nothing. I have tried in the directory
directive and that also makes no difference.
As a test the below in httpd.conf does have an affect, it re-directs, but does so to all pages i.e the condition is ignored.
RewriteEngine on
RewriteCond %SCRIPT_FILENAME !-f
RewriteCond %SCRIPT_FILENAME !-d
RewriteRule ^(.*)$ https://example.net?u=$1 [L,NC,R=301]
mod-rewrite apache2
New contributor
add a comment |Â
up vote
3
down vote
favorite
Put simply this works in htaccess:
RewriteEngine on
RewriteCond %SCRIPT_FILENAME !-f
RewriteCond %SCRIPT_FILENAME !-d
RewriteRule ^([^/]+)/?$ https://example.net?u=$1 [L,NC,R=301]
But when I move it to httpd.conf it does nothing. I have tried in the directory
directive and that also makes no difference.
As a test the below in httpd.conf does have an affect, it re-directs, but does so to all pages i.e the condition is ignored.
RewriteEngine on
RewriteCond %SCRIPT_FILENAME !-f
RewriteCond %SCRIPT_FILENAME !-d
RewriteRule ^(.*)$ https://example.net?u=$1 [L,NC,R=301]
mod-rewrite apache2
New contributor
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
Put simply this works in htaccess:
RewriteEngine on
RewriteCond %SCRIPT_FILENAME !-f
RewriteCond %SCRIPT_FILENAME !-d
RewriteRule ^([^/]+)/?$ https://example.net?u=$1 [L,NC,R=301]
But when I move it to httpd.conf it does nothing. I have tried in the directory
directive and that also makes no difference.
As a test the below in httpd.conf does have an affect, it re-directs, but does so to all pages i.e the condition is ignored.
RewriteEngine on
RewriteCond %SCRIPT_FILENAME !-f
RewriteCond %SCRIPT_FILENAME !-d
RewriteRule ^(.*)$ https://example.net?u=$1 [L,NC,R=301]
mod-rewrite apache2
New contributor
Put simply this works in htaccess:
RewriteEngine on
RewriteCond %SCRIPT_FILENAME !-f
RewriteCond %SCRIPT_FILENAME !-d
RewriteRule ^([^/]+)/?$ https://example.net?u=$1 [L,NC,R=301]
But when I move it to httpd.conf it does nothing. I have tried in the directory
directive and that also makes no difference.
As a test the below in httpd.conf does have an affect, it re-directs, but does so to all pages i.e the condition is ignored.
RewriteEngine on
RewriteCond %SCRIPT_FILENAME !-f
RewriteCond %SCRIPT_FILENAME !-d
RewriteRule ^(.*)$ https://example.net?u=$1 [L,NC,R=301]
mod-rewrite apache2
mod-rewrite apache2
New contributor
New contributor
New contributor
asked 4 hours ago
Guesser
182
182
New contributor
New contributor
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
RewriteRule ^([^/]+)/?$ https://example.net?u=$1 [L,NC,R=301]
But when I move it to httpd.conf it does nothing.
Because in a server context the RewriteRule
pattern will never match. In a server context the URL-path is root-relative, starting with a slash. In .htaccess
the URL-path is less the directory-prefix, so never starts with a slash.
I have tried in the directory directive and that also makes no difference.
That should have worked, providing you included the correct directory path. (And restarted Apache.) However, if you still had a .htaccess
file that enabled the rewrite engine then this would have overridden the server directives in the <Directory>
container, so the <Directory>
directives wouldn't have done anything still.
As a test the below in httpd.conf does have an affect, it re-directs, but does so to all pages i.e the condition is ignored.
RewriteEngine on
RewriteCond %SCRIPT_FILENAME !-f
:
Because in a server context the request has not yet been mapped to the filesystem, so SCRIPT_FILENAME
(or REQUEST_FILENAME
) does not yet contain the full filesystem path (it simply contains the URL-path), so this condition always evaluates to true (the "URL-path" being tested is not a physical file - which is probably correct).
You need to use a look-ahead instead in order to determine the final value. ie. %LA-U:REQUEST_FILENAME
.
So, in a server (or virtualhost) context you would need to use the following instead:
RewriteEngine on
RewriteCond %LA-U:REQUEST_FILENAME !-f
RewriteCond %LA-U:REQUEST_FILENAME !-d
RewriteRule ^/([^/]+)/?$ https://example.net?u=$1 [L,R=301]
Note the slash prefix on the RewriteRule
pattern.
The NC
flag is superfluous here.
1
Thank you that all makes sense, however I would have not been able to work this out for a long time I'm sure. The final section did the trick.
â Guesser
2 hours ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
RewriteRule ^([^/]+)/?$ https://example.net?u=$1 [L,NC,R=301]
But when I move it to httpd.conf it does nothing.
Because in a server context the RewriteRule
pattern will never match. In a server context the URL-path is root-relative, starting with a slash. In .htaccess
the URL-path is less the directory-prefix, so never starts with a slash.
I have tried in the directory directive and that also makes no difference.
That should have worked, providing you included the correct directory path. (And restarted Apache.) However, if you still had a .htaccess
file that enabled the rewrite engine then this would have overridden the server directives in the <Directory>
container, so the <Directory>
directives wouldn't have done anything still.
As a test the below in httpd.conf does have an affect, it re-directs, but does so to all pages i.e the condition is ignored.
RewriteEngine on
RewriteCond %SCRIPT_FILENAME !-f
:
Because in a server context the request has not yet been mapped to the filesystem, so SCRIPT_FILENAME
(or REQUEST_FILENAME
) does not yet contain the full filesystem path (it simply contains the URL-path), so this condition always evaluates to true (the "URL-path" being tested is not a physical file - which is probably correct).
You need to use a look-ahead instead in order to determine the final value. ie. %LA-U:REQUEST_FILENAME
.
So, in a server (or virtualhost) context you would need to use the following instead:
RewriteEngine on
RewriteCond %LA-U:REQUEST_FILENAME !-f
RewriteCond %LA-U:REQUEST_FILENAME !-d
RewriteRule ^/([^/]+)/?$ https://example.net?u=$1 [L,R=301]
Note the slash prefix on the RewriteRule
pattern.
The NC
flag is superfluous here.
1
Thank you that all makes sense, however I would have not been able to work this out for a long time I'm sure. The final section did the trick.
â Guesser
2 hours ago
add a comment |Â
up vote
3
down vote
accepted
RewriteRule ^([^/]+)/?$ https://example.net?u=$1 [L,NC,R=301]
But when I move it to httpd.conf it does nothing.
Because in a server context the RewriteRule
pattern will never match. In a server context the URL-path is root-relative, starting with a slash. In .htaccess
the URL-path is less the directory-prefix, so never starts with a slash.
I have tried in the directory directive and that also makes no difference.
That should have worked, providing you included the correct directory path. (And restarted Apache.) However, if you still had a .htaccess
file that enabled the rewrite engine then this would have overridden the server directives in the <Directory>
container, so the <Directory>
directives wouldn't have done anything still.
As a test the below in httpd.conf does have an affect, it re-directs, but does so to all pages i.e the condition is ignored.
RewriteEngine on
RewriteCond %SCRIPT_FILENAME !-f
:
Because in a server context the request has not yet been mapped to the filesystem, so SCRIPT_FILENAME
(or REQUEST_FILENAME
) does not yet contain the full filesystem path (it simply contains the URL-path), so this condition always evaluates to true (the "URL-path" being tested is not a physical file - which is probably correct).
You need to use a look-ahead instead in order to determine the final value. ie. %LA-U:REQUEST_FILENAME
.
So, in a server (or virtualhost) context you would need to use the following instead:
RewriteEngine on
RewriteCond %LA-U:REQUEST_FILENAME !-f
RewriteCond %LA-U:REQUEST_FILENAME !-d
RewriteRule ^/([^/]+)/?$ https://example.net?u=$1 [L,R=301]
Note the slash prefix on the RewriteRule
pattern.
The NC
flag is superfluous here.
1
Thank you that all makes sense, however I would have not been able to work this out for a long time I'm sure. The final section did the trick.
â Guesser
2 hours ago
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
RewriteRule ^([^/]+)/?$ https://example.net?u=$1 [L,NC,R=301]
But when I move it to httpd.conf it does nothing.
Because in a server context the RewriteRule
pattern will never match. In a server context the URL-path is root-relative, starting with a slash. In .htaccess
the URL-path is less the directory-prefix, so never starts with a slash.
I have tried in the directory directive and that also makes no difference.
That should have worked, providing you included the correct directory path. (And restarted Apache.) However, if you still had a .htaccess
file that enabled the rewrite engine then this would have overridden the server directives in the <Directory>
container, so the <Directory>
directives wouldn't have done anything still.
As a test the below in httpd.conf does have an affect, it re-directs, but does so to all pages i.e the condition is ignored.
RewriteEngine on
RewriteCond %SCRIPT_FILENAME !-f
:
Because in a server context the request has not yet been mapped to the filesystem, so SCRIPT_FILENAME
(or REQUEST_FILENAME
) does not yet contain the full filesystem path (it simply contains the URL-path), so this condition always evaluates to true (the "URL-path" being tested is not a physical file - which is probably correct).
You need to use a look-ahead instead in order to determine the final value. ie. %LA-U:REQUEST_FILENAME
.
So, in a server (or virtualhost) context you would need to use the following instead:
RewriteEngine on
RewriteCond %LA-U:REQUEST_FILENAME !-f
RewriteCond %LA-U:REQUEST_FILENAME !-d
RewriteRule ^/([^/]+)/?$ https://example.net?u=$1 [L,R=301]
Note the slash prefix on the RewriteRule
pattern.
The NC
flag is superfluous here.
RewriteRule ^([^/]+)/?$ https://example.net?u=$1 [L,NC,R=301]
But when I move it to httpd.conf it does nothing.
Because in a server context the RewriteRule
pattern will never match. In a server context the URL-path is root-relative, starting with a slash. In .htaccess
the URL-path is less the directory-prefix, so never starts with a slash.
I have tried in the directory directive and that also makes no difference.
That should have worked, providing you included the correct directory path. (And restarted Apache.) However, if you still had a .htaccess
file that enabled the rewrite engine then this would have overridden the server directives in the <Directory>
container, so the <Directory>
directives wouldn't have done anything still.
As a test the below in httpd.conf does have an affect, it re-directs, but does so to all pages i.e the condition is ignored.
RewriteEngine on
RewriteCond %SCRIPT_FILENAME !-f
:
Because in a server context the request has not yet been mapped to the filesystem, so SCRIPT_FILENAME
(or REQUEST_FILENAME
) does not yet contain the full filesystem path (it simply contains the URL-path), so this condition always evaluates to true (the "URL-path" being tested is not a physical file - which is probably correct).
You need to use a look-ahead instead in order to determine the final value. ie. %LA-U:REQUEST_FILENAME
.
So, in a server (or virtualhost) context you would need to use the following instead:
RewriteEngine on
RewriteCond %LA-U:REQUEST_FILENAME !-f
RewriteCond %LA-U:REQUEST_FILENAME !-d
RewriteRule ^/([^/]+)/?$ https://example.net?u=$1 [L,R=301]
Note the slash prefix on the RewriteRule
pattern.
The NC
flag is superfluous here.
edited 3 hours ago
answered 3 hours ago
DocRoot
1727
1727
1
Thank you that all makes sense, however I would have not been able to work this out for a long time I'm sure. The final section did the trick.
â Guesser
2 hours ago
add a comment |Â
1
Thank you that all makes sense, however I would have not been able to work this out for a long time I'm sure. The final section did the trick.
â Guesser
2 hours ago
1
1
Thank you that all makes sense, however I would have not been able to work this out for a long time I'm sure. The final section did the trick.
â Guesser
2 hours ago
Thank you that all makes sense, however I would have not been able to work this out for a long time I'm sure. The final section did the trick.
â Guesser
2 hours ago
add a comment |Â
Guesser is a new contributor. Be nice, and check out our Code of Conduct.
Guesser is a new contributor. Be nice, and check out our Code of Conduct.
Guesser is a new contributor. Be nice, and check out our Code of Conduct.
Guesser is a new contributor. Be nice, and check out our Code of Conduct.
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f937678%2frewritecond-ignored-in-httpd-conf%23new-answer', 'question_page');
);
Post as a guest
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
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
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