Danish
Danish

Reputation: 115

Dynamic URL rewrite help using .htaccess

How can I achieve this

Existing URL :
newsDetails.php?cid=1&nid=$5698

so I want to rewrite to new URL :

news-1/details/1000

contents of .htaccess file :

# For security reasons, Option all cannot be overridden.
#Options All -Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^news-(\d+)/[^/]+/(\d+)/?$ newsDetails.php?cid=$1&nid=$2 [L,NC,QSA]

Upvotes: 1

Views: 62

Answers (2)

anubhava
anubhava

Reputation: 784968

You can use this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On
RewriteBase /

RewriteRule ^news-(\d+)/[^/]+/(\d+)/?$ newsDetails.php?cid=$1&nid=$2 [L,NC,QSA]

Upvotes: 1

A. Blub
A. Blub

Reputation: 792

I prefere to realize it full in PHP. U need only a rewrite like

....
RewriteRule ^(.*)$ /index.php/$1 [L]

If u want to use your existing URLs, then make PHP redirects from the old files.

Upvotes: 0

Related Questions