Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I need help modify a file .htaccess delete characters from URL and redirect. The file .htaccess is currently empty.

  1. I want to change the word article to the word topic in all the URLs.

The current URL:

www.example.com/index.php?action=article&cat_id=011&id=37&lang=en
  1. I want to delete the last characters of the URLs &lang=en and some URLs &lang=

The current URLs:

www.example.com/index.php?action=article&cat_id=011&id=37&lang=en
www.example.com/?action=article&cat_id=011&id=37&lang=

So the final URL:

www.example.com/index.php?action=topic&cat_id=011&id=37
www.example.com/?action=topic&cat_id=011&id=37
share|improve this question
1  
Have you tried anything yet? –  PatomaS Mar 3 at 7:03

1 Answer 1

With the following code:

  • Line 1: Just a block header comment to explain what happens in the code snippet
  • Line 2: Requires a parameter match of the action=article value pair;
  • Line 3: Captures the cat_id value into parameter %2.
  • Line 4: Captures the id value into parameter %5.
  • Line 5: Could be used to capture the lang value (commented out / not in use).
  • Line 6: Rewrites internally to a hard-coded URL with parameters specified.

If you wished to use the lang value at some point in the future you would simply need to append &lang=%8 to the end of line 6 and remove the # comment prefix from line 5.

# Change action parameter value from article to topic and drop lang parameter
RewriteCond %{QUERY_STRING} action=article
RewriteCond %{QUERY_STRING} ^(.*&)?cat_id=([^&]+)&?(.*)?$
RewriteCond %{QUERY_STRING} ^(.*&)?id=([^&]+)&?(.*)?$
#RewriteCond %{QUERY_STRING} ^(.*&)?lang=([^&]+)&?(.*)?$
RewriteRule ^index\.php(.*)$ index.php?action=topic&cat_id=%2&id=%5
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.