RewriteRule with trailing slash
Clash Royale CLAN TAG#URR8PPP
I need to redirect some link with or without trailing slashes:
www.domain.con/foo
→ www.domain.com/redirect
(working)www.domain.com/foo/
→ www.domain.com/redirect
(not working)
I tried this rule in .htaccess
:
RewriteRule (.*)/foo/$ http://www.domain.com/redirect$1 [L,R=301]
apache-httpd
add a comment |
I need to redirect some link with or without trailing slashes:
www.domain.con/foo
→ www.domain.com/redirect
(working)www.domain.com/foo/
→ www.domain.com/redirect
(not working)
I tried this rule in .htaccess
:
RewriteRule (.*)/foo/$ http://www.domain.com/redirect$1 [L,R=301]
apache-httpd
add a comment |
I need to redirect some link with or without trailing slashes:
www.domain.con/foo
→ www.domain.com/redirect
(working)www.domain.com/foo/
→ www.domain.com/redirect
(not working)
I tried this rule in .htaccess
:
RewriteRule (.*)/foo/$ http://www.domain.com/redirect$1 [L,R=301]
apache-httpd
I need to redirect some link with or without trailing slashes:
www.domain.con/foo
→ www.domain.com/redirect
(working)www.domain.com/foo/
→ www.domain.com/redirect
(not working)
I tried this rule in .htaccess
:
RewriteRule (.*)/foo/$ http://www.domain.com/redirect$1 [L,R=301]
apache-httpd
apache-httpd
edited Sep 30 '14 at 21:21
Gilles
538k12810881605
538k12810881605
asked Sep 30 '14 at 9:14
hellb0y77hellb0y77
84162038
84162038
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
To redirect www.domain.com/foo
or www.domain.com/foo/
to www.domain.com/redirect
you need to make the match on the trailing slash optional with a question mark (/?
):
RewriteRule ^foo/?$ http://www.domain.com/redirect [L,R=301]
Same problem, don't work
– hellb0y77
Sep 30 '14 at 13:30
To resolve partially i have make a 301 redirect that work without trailing slashRedirect 301 /foo http://www.domain.com/redirect
but with trailing slash and RewriteRule i have a double/
es.http://www.domain.com/redirect//
– hellb0y77
Sep 30 '14 at 13:43
That's very odd. I've just ran a test on an Amazon EC2 instance and it does work. How are you testing? I usedwget -O /dev/null --no-cache <url>
to make sure that my browser wasn't caching anything. The above command will show the 301 redirect.
– garethTheRed
Sep 30 '14 at 14:46
i tried to moveRewriteRule
from .htaccess to /etc/httpd/conf.d/myconf.conf inside<Virtualhost>
directive and my original rules works (RewriteRule (.*)/foo/$ http://www.domain.com/redirect$1 [L,R=301]
). It's possible thatRewriteRule
works only in a vitrualhost directive?
– hellb0y77
Sep 30 '14 at 16:15
From the Apache documentation,RewriteRule
works in server config, virtual host, directory, .htaccess
– garethTheRed
Sep 30 '14 at 19:16
add a comment |
RewriteRule ^foo/?$ http://www.domain.com/redirect [L,R=301]
This is a correct solution but will not carry the variable over, just a page to page. If you are having caching issues I recommend using https://httpstatus.io/ to verify the redirects as it doesn't seem to cache any of the redirect information. Also, testing using 302 instead of 301 will keep the browser from being stubborn about giving up the cached page location.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2funix.stackexchange.com%2fquestions%2f158380%2frewriterule-with-trailing-slash%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
To redirect www.domain.com/foo
or www.domain.com/foo/
to www.domain.com/redirect
you need to make the match on the trailing slash optional with a question mark (/?
):
RewriteRule ^foo/?$ http://www.domain.com/redirect [L,R=301]
Same problem, don't work
– hellb0y77
Sep 30 '14 at 13:30
To resolve partially i have make a 301 redirect that work without trailing slashRedirect 301 /foo http://www.domain.com/redirect
but with trailing slash and RewriteRule i have a double/
es.http://www.domain.com/redirect//
– hellb0y77
Sep 30 '14 at 13:43
That's very odd. I've just ran a test on an Amazon EC2 instance and it does work. How are you testing? I usedwget -O /dev/null --no-cache <url>
to make sure that my browser wasn't caching anything. The above command will show the 301 redirect.
– garethTheRed
Sep 30 '14 at 14:46
i tried to moveRewriteRule
from .htaccess to /etc/httpd/conf.d/myconf.conf inside<Virtualhost>
directive and my original rules works (RewriteRule (.*)/foo/$ http://www.domain.com/redirect$1 [L,R=301]
). It's possible thatRewriteRule
works only in a vitrualhost directive?
– hellb0y77
Sep 30 '14 at 16:15
From the Apache documentation,RewriteRule
works in server config, virtual host, directory, .htaccess
– garethTheRed
Sep 30 '14 at 19:16
add a comment |
To redirect www.domain.com/foo
or www.domain.com/foo/
to www.domain.com/redirect
you need to make the match on the trailing slash optional with a question mark (/?
):
RewriteRule ^foo/?$ http://www.domain.com/redirect [L,R=301]
Same problem, don't work
– hellb0y77
Sep 30 '14 at 13:30
To resolve partially i have make a 301 redirect that work without trailing slashRedirect 301 /foo http://www.domain.com/redirect
but with trailing slash and RewriteRule i have a double/
es.http://www.domain.com/redirect//
– hellb0y77
Sep 30 '14 at 13:43
That's very odd. I've just ran a test on an Amazon EC2 instance and it does work. How are you testing? I usedwget -O /dev/null --no-cache <url>
to make sure that my browser wasn't caching anything. The above command will show the 301 redirect.
– garethTheRed
Sep 30 '14 at 14:46
i tried to moveRewriteRule
from .htaccess to /etc/httpd/conf.d/myconf.conf inside<Virtualhost>
directive and my original rules works (RewriteRule (.*)/foo/$ http://www.domain.com/redirect$1 [L,R=301]
). It's possible thatRewriteRule
works only in a vitrualhost directive?
– hellb0y77
Sep 30 '14 at 16:15
From the Apache documentation,RewriteRule
works in server config, virtual host, directory, .htaccess
– garethTheRed
Sep 30 '14 at 19:16
add a comment |
To redirect www.domain.com/foo
or www.domain.com/foo/
to www.domain.com/redirect
you need to make the match on the trailing slash optional with a question mark (/?
):
RewriteRule ^foo/?$ http://www.domain.com/redirect [L,R=301]
To redirect www.domain.com/foo
or www.domain.com/foo/
to www.domain.com/redirect
you need to make the match on the trailing slash optional with a question mark (/?
):
RewriteRule ^foo/?$ http://www.domain.com/redirect [L,R=301]
answered Sep 30 '14 at 11:42
garethTheRedgarethTheRed
24.5k36280
24.5k36280
Same problem, don't work
– hellb0y77
Sep 30 '14 at 13:30
To resolve partially i have make a 301 redirect that work without trailing slashRedirect 301 /foo http://www.domain.com/redirect
but with trailing slash and RewriteRule i have a double/
es.http://www.domain.com/redirect//
– hellb0y77
Sep 30 '14 at 13:43
That's very odd. I've just ran a test on an Amazon EC2 instance and it does work. How are you testing? I usedwget -O /dev/null --no-cache <url>
to make sure that my browser wasn't caching anything. The above command will show the 301 redirect.
– garethTheRed
Sep 30 '14 at 14:46
i tried to moveRewriteRule
from .htaccess to /etc/httpd/conf.d/myconf.conf inside<Virtualhost>
directive and my original rules works (RewriteRule (.*)/foo/$ http://www.domain.com/redirect$1 [L,R=301]
). It's possible thatRewriteRule
works only in a vitrualhost directive?
– hellb0y77
Sep 30 '14 at 16:15
From the Apache documentation,RewriteRule
works in server config, virtual host, directory, .htaccess
– garethTheRed
Sep 30 '14 at 19:16
add a comment |
Same problem, don't work
– hellb0y77
Sep 30 '14 at 13:30
To resolve partially i have make a 301 redirect that work without trailing slashRedirect 301 /foo http://www.domain.com/redirect
but with trailing slash and RewriteRule i have a double/
es.http://www.domain.com/redirect//
– hellb0y77
Sep 30 '14 at 13:43
That's very odd. I've just ran a test on an Amazon EC2 instance and it does work. How are you testing? I usedwget -O /dev/null --no-cache <url>
to make sure that my browser wasn't caching anything. The above command will show the 301 redirect.
– garethTheRed
Sep 30 '14 at 14:46
i tried to moveRewriteRule
from .htaccess to /etc/httpd/conf.d/myconf.conf inside<Virtualhost>
directive and my original rules works (RewriteRule (.*)/foo/$ http://www.domain.com/redirect$1 [L,R=301]
). It's possible thatRewriteRule
works only in a vitrualhost directive?
– hellb0y77
Sep 30 '14 at 16:15
From the Apache documentation,RewriteRule
works in server config, virtual host, directory, .htaccess
– garethTheRed
Sep 30 '14 at 19:16
Same problem, don't work
– hellb0y77
Sep 30 '14 at 13:30
Same problem, don't work
– hellb0y77
Sep 30 '14 at 13:30
To resolve partially i have make a 301 redirect that work without trailing slash
Redirect 301 /foo http://www.domain.com/redirect
but with trailing slash and RewriteRule i have a double /
es. http://www.domain.com/redirect//
– hellb0y77
Sep 30 '14 at 13:43
To resolve partially i have make a 301 redirect that work without trailing slash
Redirect 301 /foo http://www.domain.com/redirect
but with trailing slash and RewriteRule i have a double /
es. http://www.domain.com/redirect//
– hellb0y77
Sep 30 '14 at 13:43
That's very odd. I've just ran a test on an Amazon EC2 instance and it does work. How are you testing? I used
wget -O /dev/null --no-cache <url>
to make sure that my browser wasn't caching anything. The above command will show the 301 redirect.– garethTheRed
Sep 30 '14 at 14:46
That's very odd. I've just ran a test on an Amazon EC2 instance and it does work. How are you testing? I used
wget -O /dev/null --no-cache <url>
to make sure that my browser wasn't caching anything. The above command will show the 301 redirect.– garethTheRed
Sep 30 '14 at 14:46
i tried to move
RewriteRule
from .htaccess to /etc/httpd/conf.d/myconf.conf inside <Virtualhost>
directive and my original rules works (RewriteRule (.*)/foo/$ http://www.domain.com/redirect$1 [L,R=301]
). It's possible that RewriteRule
works only in a vitrualhost directive?– hellb0y77
Sep 30 '14 at 16:15
i tried to move
RewriteRule
from .htaccess to /etc/httpd/conf.d/myconf.conf inside <Virtualhost>
directive and my original rules works (RewriteRule (.*)/foo/$ http://www.domain.com/redirect$1 [L,R=301]
). It's possible that RewriteRule
works only in a vitrualhost directive?– hellb0y77
Sep 30 '14 at 16:15
From the Apache documentation,
RewriteRule
works in server config, virtual host, directory, .htaccess– garethTheRed
Sep 30 '14 at 19:16
From the Apache documentation,
RewriteRule
works in server config, virtual host, directory, .htaccess– garethTheRed
Sep 30 '14 at 19:16
add a comment |
RewriteRule ^foo/?$ http://www.domain.com/redirect [L,R=301]
This is a correct solution but will not carry the variable over, just a page to page. If you are having caching issues I recommend using https://httpstatus.io/ to verify the redirects as it doesn't seem to cache any of the redirect information. Also, testing using 302 instead of 301 will keep the browser from being stubborn about giving up the cached page location.
add a comment |
RewriteRule ^foo/?$ http://www.domain.com/redirect [L,R=301]
This is a correct solution but will not carry the variable over, just a page to page. If you are having caching issues I recommend using https://httpstatus.io/ to verify the redirects as it doesn't seem to cache any of the redirect information. Also, testing using 302 instead of 301 will keep the browser from being stubborn about giving up the cached page location.
add a comment |
RewriteRule ^foo/?$ http://www.domain.com/redirect [L,R=301]
This is a correct solution but will not carry the variable over, just a page to page. If you are having caching issues I recommend using https://httpstatus.io/ to verify the redirects as it doesn't seem to cache any of the redirect information. Also, testing using 302 instead of 301 will keep the browser from being stubborn about giving up the cached page location.
RewriteRule ^foo/?$ http://www.domain.com/redirect [L,R=301]
This is a correct solution but will not carry the variable over, just a page to page. If you are having caching issues I recommend using https://httpstatus.io/ to verify the redirects as it doesn't seem to cache any of the redirect information. Also, testing using 302 instead of 301 will keep the browser from being stubborn about giving up the cached page location.
answered Aug 8 '17 at 15:24
Rich SRich S
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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%2funix.stackexchange.com%2fquestions%2f158380%2frewriterule-with-trailing-slash%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