skip to Main Content

I would like to know if it is possible to format a URL like https://site1.com/en/article-details.test-article?item=test to https://site1.com/en/article-details/test-article?item=test so basically changing the .test-article to /test-article.

Because of how my site works it only recognizes .test-article as a valid selector so reading up https://httpd.apache.org/docs/2.4/rewrite/flags.html it seems I may need to use a PT flag to show the user the desired URL but pass the correct one to my site.

So far I have this to replace the dot for a slash

RewriteCond %{REQUEST_URI} ^/([a-z]{2})/article-details.([a-z]{2})(/?)$
RewriteRule ^/([a-z]{2})/.*  https://%{SERVER_NAME}/$1/$2 [L,NC,R=301]

Edit(this works to format the URL as per RavinderSingh13’s suggestion)

RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/([a-z]{2})/article-details.([^?]*)(/?)$
RewriteRule ^ https://%{SERVER_NAME}/%1/article-details/%2 [QSA,R=301,NE,L]

2

Answers


  1. With your shown samples, could you please try following. Please make sure you clear your browser cache before testing your URLs.

    RewriteEngine ON
    RewriteCond %{THE_REQUEST} s/(en/article-details).(test-article)?item=tests [NC]
    RewriteRule ^ https://site1.com/%1/%2 [QSA,R=301,NE,L]
    

    As per OP’s comments adding more Generic rules here:

    RewriteEngine ON
    RewriteCond %{THE_REQUEST} s/(en/article-details).([^?]*)?item=tests [NC]
    RewriteRule ^ https://site1.com/%1/%2 [QSA,R=301,NE,L]
    
    Login or Signup to reply.
  2. You may try this rule as your topmost rule:

    RewriteEngine On
    
    RewriteRule ^(.+).(test-article/?)$ /$1/$2 [R=302,NE,L,NC]
    

    Change 302 to 301 after testing this rule.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search