amadeo
amadeo

Reputation: 109

How to change php urls on my website?

Is it possible to somehow change my website links from:

domain.com/category.php?tag=test
domain.com/section.php?tag=test
domain.com/news.php?tag=test

into this:

domain.com/category-test
domain.com/section-test
domain.com/news-test

Thanks and have a good day!

Upvotes: 0

Views: 81

Answers (2)

BenM
BenM

Reputation: 53246

You can achieve this using .htaccess and mod_rewrite. You'll need to create a .htaccess file with the following contents:

RewriteEngine On
RewriteBase /

RewriteRule ^category-([^/]+)/?$ category.php?tag=$1
RewriteRule ^section-([^/]+)/?$ section.php?tag=$1
RewriteRule ^news-([^/]+)/?$ news.php?tag=$1

Now, accessing domain.com/category-test/ will take you to category.php?tag=test.

If you'd prefer to have slashes instead of dashes, you can use:

RewriteRule ^category/([^/]+)/?$ category.php?tag=$1
RewriteRule ^section/([^/]+)/?$ section.php?tag=$1
RewriteRule ^news/([^/]+)/?$ news.php?tag=$1

Upvotes: 1

alreadycoded.com
alreadycoded.com

Reputation: 326

RewriteRule ^category-([a-zA-Z0-9]+)$ category.php?tag=$1 [NC,L]
RewriteRule ^section-([a-zA-Z0-9]+)$ section.php?tag=$1 [NC,L]
RewriteRule ^news-([a-zA-Z0-9]+)$ news.php?tag=$1 [NC,L]

In "category.php" file get the tag $_GET['tag'];

Upvotes: 0

Related Questions