Dmitry G
Dmitry G

Reputation: 93

How to rewrite part of URL in .htaccess?

I have this URL:

example.com/news/article/254

How to make a PHP script to process this URL (example.com/blog/article/254) as example.com/news/article/254, and example.com/blog as example.com/news, etc.

Upvotes: 0

Views: 93

Answers (1)

searaig
searaig

Reputation: 61

The following code should work if you add it to your .htaccess file.

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteRule ^blog/article/(.+?)\/?$ /news/article/$1 [R=301, L]
</IfModule>

If you don't want to tell robots etc. that you have permanently redirected then take out the "R=301, " above.

Upvotes: 1

Related Questions