Johan Larsson
Johan Larsson

Reputation: 175

mod_rewrite static URL to dynamic

How to rewrite this URL

http://www.domain.com/folder/number/50.html

to

http://www.domain.com/folder/number?id=50#50

Appreciate your help.

Upvotes: 0

Views: 74

Answers (2)

Felipe Alameda A
Felipe Alameda A

Reputation: 11809

You may try this in the .htaccess file in root directory:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^folder/number/([^/]+)\.html/?  /folder/number?id=$1#$1  [NE,NC,L]

Map silently

http://www.domain.com/folder/number/50.html with or without trailing slash

To:

http://www.domain.com/folder/number?id=50#50

String 50 is assumed to be dynamic.

For permanent and visible redirection, replace [NE,NC,L] with [R=301,NE,NC,L]

Upvotes: 1

zessx
zessx

Reputation: 68790

Here's the simplest way to do it :

RewriteEngine On
RewriteBase /
RewriteRule ^folder/number/(\d+)\.html$ folder/number?id=$1#$1 [L,R=301]

Change [L,R=301] to [L] if you want this redirection to be transparent.

Upvotes: 0

Related Questions