Regex 301 Redirect .htaccess file [closed]










2















I need to redirect ALL instances of example.com/privacy-policy to a new domain page.



For example, redirect example.com/privacy-policy AND example.com/subfolder/privacy-policy



This is what I have:



RedirectMatch 301 ^/privacy-policy/(.+?)(-[0-9]+)?$ https://new.example/privacy-policy/v2/


I'm not having any luck and I'm struggling with other versions of this.



What am I missing?










share|improve this question















closed as off-topic by Andrejs Cainikovs, Patrick Mevzek, lucascaro, Graham, Shiladitya Nov 15 '18 at 4:51


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions on professional server- or networking-related infrastructure administration are off-topic for Stack Overflow unless they directly involve programming or programming tools. You may be able to get help on Server Fault." – Andrejs Cainikovs, Patrick Mevzek, lucascaro, Graham, Shiladitya
If this question can be reworded to fit the rules in the help center, please edit the question.
















  • Try serverfault.com instead.

    – Andrejs Cainikovs
    Nov 14 '18 at 17:00











  • Redirects in .htaccess are better suited to webmasters.stackexchange.com (not ServerFault).

    – MrWhite
    Nov 15 '18 at 0:27












  • This forum is widely used for questions on htaccess, mod_rewrite and regex hence there is nothing wrong in asking it here.

    – anubhava
    Nov 15 '18 at 10:42















2















I need to redirect ALL instances of example.com/privacy-policy to a new domain page.



For example, redirect example.com/privacy-policy AND example.com/subfolder/privacy-policy



This is what I have:



RedirectMatch 301 ^/privacy-policy/(.+?)(-[0-9]+)?$ https://new.example/privacy-policy/v2/


I'm not having any luck and I'm struggling with other versions of this.



What am I missing?










share|improve this question















closed as off-topic by Andrejs Cainikovs, Patrick Mevzek, lucascaro, Graham, Shiladitya Nov 15 '18 at 4:51


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions on professional server- or networking-related infrastructure administration are off-topic for Stack Overflow unless they directly involve programming or programming tools. You may be able to get help on Server Fault." – Andrejs Cainikovs, Patrick Mevzek, lucascaro, Graham, Shiladitya
If this question can be reworded to fit the rules in the help center, please edit the question.
















  • Try serverfault.com instead.

    – Andrejs Cainikovs
    Nov 14 '18 at 17:00











  • Redirects in .htaccess are better suited to webmasters.stackexchange.com (not ServerFault).

    – MrWhite
    Nov 15 '18 at 0:27












  • This forum is widely used for questions on htaccess, mod_rewrite and regex hence there is nothing wrong in asking it here.

    – anubhava
    Nov 15 '18 at 10:42













2












2








2








I need to redirect ALL instances of example.com/privacy-policy to a new domain page.



For example, redirect example.com/privacy-policy AND example.com/subfolder/privacy-policy



This is what I have:



RedirectMatch 301 ^/privacy-policy/(.+?)(-[0-9]+)?$ https://new.example/privacy-policy/v2/


I'm not having any luck and I'm struggling with other versions of this.



What am I missing?










share|improve this question
















I need to redirect ALL instances of example.com/privacy-policy to a new domain page.



For example, redirect example.com/privacy-policy AND example.com/subfolder/privacy-policy



This is what I have:



RedirectMatch 301 ^/privacy-policy/(.+?)(-[0-9]+)?$ https://new.example/privacy-policy/v2/


I'm not having any luck and I'm struggling with other versions of this.



What am I missing?







.htaccess url redirect






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 0:04









MrWhite

12.9k33161




12.9k33161










asked Nov 14 '18 at 16:59









WGMWGM

133




133




closed as off-topic by Andrejs Cainikovs, Patrick Mevzek, lucascaro, Graham, Shiladitya Nov 15 '18 at 4:51


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions on professional server- or networking-related infrastructure administration are off-topic for Stack Overflow unless they directly involve programming or programming tools. You may be able to get help on Server Fault." – Andrejs Cainikovs, Patrick Mevzek, lucascaro, Graham, Shiladitya
If this question can be reworded to fit the rules in the help center, please edit the question.







closed as off-topic by Andrejs Cainikovs, Patrick Mevzek, lucascaro, Graham, Shiladitya Nov 15 '18 at 4:51


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions on professional server- or networking-related infrastructure administration are off-topic for Stack Overflow unless they directly involve programming or programming tools. You may be able to get help on Server Fault." – Andrejs Cainikovs, Patrick Mevzek, lucascaro, Graham, Shiladitya
If this question can be reworded to fit the rules in the help center, please edit the question.












  • Try serverfault.com instead.

    – Andrejs Cainikovs
    Nov 14 '18 at 17:00











  • Redirects in .htaccess are better suited to webmasters.stackexchange.com (not ServerFault).

    – MrWhite
    Nov 15 '18 at 0:27












  • This forum is widely used for questions on htaccess, mod_rewrite and regex hence there is nothing wrong in asking it here.

    – anubhava
    Nov 15 '18 at 10:42

















  • Try serverfault.com instead.

    – Andrejs Cainikovs
    Nov 14 '18 at 17:00











  • Redirects in .htaccess are better suited to webmasters.stackexchange.com (not ServerFault).

    – MrWhite
    Nov 15 '18 at 0:27












  • This forum is widely used for questions on htaccess, mod_rewrite and regex hence there is nothing wrong in asking it here.

    – anubhava
    Nov 15 '18 at 10:42
















Try serverfault.com instead.

– Andrejs Cainikovs
Nov 14 '18 at 17:00





Try serverfault.com instead.

– Andrejs Cainikovs
Nov 14 '18 at 17:00













Redirects in .htaccess are better suited to webmasters.stackexchange.com (not ServerFault).

– MrWhite
Nov 15 '18 at 0:27






Redirects in .htaccess are better suited to webmasters.stackexchange.com (not ServerFault).

– MrWhite
Nov 15 '18 at 0:27














This forum is widely used for questions on htaccess, mod_rewrite and regex hence there is nothing wrong in asking it here.

– anubhava
Nov 15 '18 at 10:42





This forum is widely used for questions on htaccess, mod_rewrite and regex hence there is nothing wrong in asking it here.

– anubhava
Nov 15 '18 at 10:42












1 Answer
1






active

oldest

votes


















1














You can use this rule with a tweak in your regex:



RedirectMatch 301 /privacy-policy(/.*)?$ https://new.example/privacy-policy/v2/


  • By removing ^ from regex we are now matching /privacy-policy anywhere in URI not just the start.

  • Since you don't care what comes after /privacy-policy, there is no reason to match anything but optional /.* in the end.

  • Make sure to use a new browser for your testing.





share|improve this answer




















  • 1





    Perfect! Thank you! I don't want to violate any forum rules here, but you can you briefly explain the error in my syntax vs yours? If not, thanks again!

    – WGM
    Nov 14 '18 at 17:10

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You can use this rule with a tweak in your regex:



RedirectMatch 301 /privacy-policy(/.*)?$ https://new.example/privacy-policy/v2/


  • By removing ^ from regex we are now matching /privacy-policy anywhere in URI not just the start.

  • Since you don't care what comes after /privacy-policy, there is no reason to match anything but optional /.* in the end.

  • Make sure to use a new browser for your testing.





share|improve this answer




















  • 1





    Perfect! Thank you! I don't want to violate any forum rules here, but you can you briefly explain the error in my syntax vs yours? If not, thanks again!

    – WGM
    Nov 14 '18 at 17:10















1














You can use this rule with a tweak in your regex:



RedirectMatch 301 /privacy-policy(/.*)?$ https://new.example/privacy-policy/v2/


  • By removing ^ from regex we are now matching /privacy-policy anywhere in URI not just the start.

  • Since you don't care what comes after /privacy-policy, there is no reason to match anything but optional /.* in the end.

  • Make sure to use a new browser for your testing.





share|improve this answer




















  • 1





    Perfect! Thank you! I don't want to violate any forum rules here, but you can you briefly explain the error in my syntax vs yours? If not, thanks again!

    – WGM
    Nov 14 '18 at 17:10













1












1








1







You can use this rule with a tweak in your regex:



RedirectMatch 301 /privacy-policy(/.*)?$ https://new.example/privacy-policy/v2/


  • By removing ^ from regex we are now matching /privacy-policy anywhere in URI not just the start.

  • Since you don't care what comes after /privacy-policy, there is no reason to match anything but optional /.* in the end.

  • Make sure to use a new browser for your testing.





share|improve this answer















You can use this rule with a tweak in your regex:



RedirectMatch 301 /privacy-policy(/.*)?$ https://new.example/privacy-policy/v2/


  • By removing ^ from regex we are now matching /privacy-policy anywhere in URI not just the start.

  • Since you don't care what comes after /privacy-policy, there is no reason to match anything but optional /.* in the end.

  • Make sure to use a new browser for your testing.






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 15 '18 at 0:07









MrWhite

12.9k33161




12.9k33161










answered Nov 14 '18 at 17:04









anubhavaanubhava

529k46329404




529k46329404







  • 1





    Perfect! Thank you! I don't want to violate any forum rules here, but you can you briefly explain the error in my syntax vs yours? If not, thanks again!

    – WGM
    Nov 14 '18 at 17:10












  • 1





    Perfect! Thank you! I don't want to violate any forum rules here, but you can you briefly explain the error in my syntax vs yours? If not, thanks again!

    – WGM
    Nov 14 '18 at 17:10







1




1





Perfect! Thank you! I don't want to violate any forum rules here, but you can you briefly explain the error in my syntax vs yours? If not, thanks again!

– WGM
Nov 14 '18 at 17:10





Perfect! Thank you! I don't want to violate any forum rules here, but you can you briefly explain the error in my syntax vs yours? If not, thanks again!

– WGM
Nov 14 '18 at 17:10





這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto