How to redirect dynamically generated duplicate pages in .htaccess?
I have over 2000 dynamically generated duplicated pages like this:
https://www.example.com/subfolder/page1.html
and
https://www.example.com/subfolder/page1/
What i am trying to do is redirect all /subfolder/all-pages.html to /subfolder/all-pages/
Since it is very complicated to make those pages canonical as i use a custom script, how do i get to do this? One extra question if you dont mind, would that not be too much redirected pages for Google and SEO? It already hurt my SEO a lot. Thanks!
htaccess redirects 301-redirect
add a comment |
I have over 2000 dynamically generated duplicated pages like this:
https://www.example.com/subfolder/page1.html
and
https://www.example.com/subfolder/page1/
What i am trying to do is redirect all /subfolder/all-pages.html to /subfolder/all-pages/
Since it is very complicated to make those pages canonical as i use a custom script, how do i get to do this? One extra question if you dont mind, would that not be too much redirected pages for Google and SEO? It already hurt my SEO a lot. Thanks!
htaccess redirects 301-redirect
It would be useful to see your existing.htaccessfile as this would enable the solution to be better optimised for your particular case.
– MrWhite
8 hours ago
add a comment |
I have over 2000 dynamically generated duplicated pages like this:
https://www.example.com/subfolder/page1.html
and
https://www.example.com/subfolder/page1/
What i am trying to do is redirect all /subfolder/all-pages.html to /subfolder/all-pages/
Since it is very complicated to make those pages canonical as i use a custom script, how do i get to do this? One extra question if you dont mind, would that not be too much redirected pages for Google and SEO? It already hurt my SEO a lot. Thanks!
htaccess redirects 301-redirect
I have over 2000 dynamically generated duplicated pages like this:
https://www.example.com/subfolder/page1.html
and
https://www.example.com/subfolder/page1/
What i am trying to do is redirect all /subfolder/all-pages.html to /subfolder/all-pages/
Since it is very complicated to make those pages canonical as i use a custom script, how do i get to do this? One extra question if you dont mind, would that not be too much redirected pages for Google and SEO? It already hurt my SEO a lot. Thanks!
htaccess redirects 301-redirect
htaccess redirects 301-redirect
asked 9 hours ago
paranoicparanoic
425
425
It would be useful to see your existing.htaccessfile as this would enable the solution to be better optimised for your particular case.
– MrWhite
8 hours ago
add a comment |
It would be useful to see your existing.htaccessfile as this would enable the solution to be better optimised for your particular case.
– MrWhite
8 hours ago
It would be useful to see your existing
.htaccess file as this would enable the solution to be better optimised for your particular case.– MrWhite
8 hours ago
It would be useful to see your existing
.htaccess file as this would enable the solution to be better optimised for your particular case.– MrWhite
8 hours ago
add a comment |
1 Answer
1
active
oldest
votes
I assume you are already linking to the URL of the form: /subfolder/page1/. In which case, you can do something like the following using mod_rewrite near the top of your .htaccess file in the root of your site:
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(subfolder/[^/]+).html$ /$1/ [R=302,L]
The RewriteCond directive that checks against the REDIRECT_STATUS environment variable may be required in order to prevent a rewrite loop (although whether this is required or not is dependent on how you are routing/rewriting your URLs later).
Note that this is a 302 (temporary) redirect. Only change to a 301 (permanent) redirect - if that is the intention - when you are sure it's working OK. This avoids any erroneous redirects being cached by the browser.
However, simply having these two URLs accessible should not have "hurt your SEO a lot", providing you were consistent in always linking to one version. (Unless you changed the URL structure later?)
thank you @MrWhite , this worked perfectly! i only have concerns now, since this is 302 redirect which is not very SEO friendly, how do i change it to 301? just instead 302 write 301 or what? thanks once again this solved much more problems than only duplicate pages
– paranoic
6 hours ago
@paranoic Yes, that's the change to make. Be 100% sure it's working first, though!
– wizzwizz4
4 hours ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "45"
};
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%2fwebmasters.stackexchange.com%2fquestions%2f121485%2fhow-to-redirect-dynamically-generated-duplicate-pages-in-htaccess%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
I assume you are already linking to the URL of the form: /subfolder/page1/. In which case, you can do something like the following using mod_rewrite near the top of your .htaccess file in the root of your site:
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(subfolder/[^/]+).html$ /$1/ [R=302,L]
The RewriteCond directive that checks against the REDIRECT_STATUS environment variable may be required in order to prevent a rewrite loop (although whether this is required or not is dependent on how you are routing/rewriting your URLs later).
Note that this is a 302 (temporary) redirect. Only change to a 301 (permanent) redirect - if that is the intention - when you are sure it's working OK. This avoids any erroneous redirects being cached by the browser.
However, simply having these two URLs accessible should not have "hurt your SEO a lot", providing you were consistent in always linking to one version. (Unless you changed the URL structure later?)
thank you @MrWhite , this worked perfectly! i only have concerns now, since this is 302 redirect which is not very SEO friendly, how do i change it to 301? just instead 302 write 301 or what? thanks once again this solved much more problems than only duplicate pages
– paranoic
6 hours ago
@paranoic Yes, that's the change to make. Be 100% sure it's working first, though!
– wizzwizz4
4 hours ago
add a comment |
I assume you are already linking to the URL of the form: /subfolder/page1/. In which case, you can do something like the following using mod_rewrite near the top of your .htaccess file in the root of your site:
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(subfolder/[^/]+).html$ /$1/ [R=302,L]
The RewriteCond directive that checks against the REDIRECT_STATUS environment variable may be required in order to prevent a rewrite loop (although whether this is required or not is dependent on how you are routing/rewriting your URLs later).
Note that this is a 302 (temporary) redirect. Only change to a 301 (permanent) redirect - if that is the intention - when you are sure it's working OK. This avoids any erroneous redirects being cached by the browser.
However, simply having these two URLs accessible should not have "hurt your SEO a lot", providing you were consistent in always linking to one version. (Unless you changed the URL structure later?)
thank you @MrWhite , this worked perfectly! i only have concerns now, since this is 302 redirect which is not very SEO friendly, how do i change it to 301? just instead 302 write 301 or what? thanks once again this solved much more problems than only duplicate pages
– paranoic
6 hours ago
@paranoic Yes, that's the change to make. Be 100% sure it's working first, though!
– wizzwizz4
4 hours ago
add a comment |
I assume you are already linking to the URL of the form: /subfolder/page1/. In which case, you can do something like the following using mod_rewrite near the top of your .htaccess file in the root of your site:
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(subfolder/[^/]+).html$ /$1/ [R=302,L]
The RewriteCond directive that checks against the REDIRECT_STATUS environment variable may be required in order to prevent a rewrite loop (although whether this is required or not is dependent on how you are routing/rewriting your URLs later).
Note that this is a 302 (temporary) redirect. Only change to a 301 (permanent) redirect - if that is the intention - when you are sure it's working OK. This avoids any erroneous redirects being cached by the browser.
However, simply having these two URLs accessible should not have "hurt your SEO a lot", providing you were consistent in always linking to one version. (Unless you changed the URL structure later?)
I assume you are already linking to the URL of the form: /subfolder/page1/. In which case, you can do something like the following using mod_rewrite near the top of your .htaccess file in the root of your site:
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(subfolder/[^/]+).html$ /$1/ [R=302,L]
The RewriteCond directive that checks against the REDIRECT_STATUS environment variable may be required in order to prevent a rewrite loop (although whether this is required or not is dependent on how you are routing/rewriting your URLs later).
Note that this is a 302 (temporary) redirect. Only change to a 301 (permanent) redirect - if that is the intention - when you are sure it's working OK. This avoids any erroneous redirects being cached by the browser.
However, simply having these two URLs accessible should not have "hurt your SEO a lot", providing you were consistent in always linking to one version. (Unless you changed the URL structure later?)
answered 8 hours ago
MrWhiteMrWhite
31.7k33366
31.7k33366
thank you @MrWhite , this worked perfectly! i only have concerns now, since this is 302 redirect which is not very SEO friendly, how do i change it to 301? just instead 302 write 301 or what? thanks once again this solved much more problems than only duplicate pages
– paranoic
6 hours ago
@paranoic Yes, that's the change to make. Be 100% sure it's working first, though!
– wizzwizz4
4 hours ago
add a comment |
thank you @MrWhite , this worked perfectly! i only have concerns now, since this is 302 redirect which is not very SEO friendly, how do i change it to 301? just instead 302 write 301 or what? thanks once again this solved much more problems than only duplicate pages
– paranoic
6 hours ago
@paranoic Yes, that's the change to make. Be 100% sure it's working first, though!
– wizzwizz4
4 hours ago
thank you @MrWhite , this worked perfectly! i only have concerns now, since this is 302 redirect which is not very SEO friendly, how do i change it to 301? just instead 302 write 301 or what? thanks once again this solved much more problems than only duplicate pages
– paranoic
6 hours ago
thank you @MrWhite , this worked perfectly! i only have concerns now, since this is 302 redirect which is not very SEO friendly, how do i change it to 301? just instead 302 write 301 or what? thanks once again this solved much more problems than only duplicate pages
– paranoic
6 hours ago
@paranoic Yes, that's the change to make. Be 100% sure it's working first, though!
– wizzwizz4
4 hours ago
@paranoic Yes, that's the change to make. Be 100% sure it's working first, though!
– wizzwizz4
4 hours ago
add a comment |
Thanks for contributing an answer to Webmasters 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%2fwebmasters.stackexchange.com%2fquestions%2f121485%2fhow-to-redirect-dynamically-generated-duplicate-pages-in-htaccess%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
It would be useful to see your existing
.htaccessfile as this would enable the solution to be better optimised for your particular case.– MrWhite
8 hours ago