Mobile app version of vmapp.org
Login or Join
Caterina187

: .htaccess - delete characters from URL and redirect I need help modify a file .htaccess delete characters from URL and redirect. The file .htaccess is currently empty. I want to change the word

@Caterina187

Posted in: #Htaccess #Redirects

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


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


The current URL:
example.com/index.php?action=article&cat_id=011&id=37&lang=en


I want to delete the last characters of the URLs &lang=en and some URLs &lang=


The current URLs:
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:
example.com/index.php?action=topic&cat_id=011&id=37 www.example.com/?action=topic&cat_id=011&id=37

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Caterina187

1 Comments

Sorted by latest first Latest Oldest Best

 

@Cugini213

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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme