Daniel
Daniel

Reputation: 37

How do I rewrite this URL for .htaccess?

I have many tag URL's that need to be changed to a new domain permalink structure.

I need some help please with a rewrite rule for my .htaccess file.

Old URL:

domain.com/tags/TAGNAME.html

New URL:

domain.com/tags/TAGNAME/

Where TAGNAME changes, respectively.

Any help would be greatly appreciated. Thanks in advance.

Upvotes: 1

Views: 62

Answers (2)

MrWhite
MrWhite

Reputation: 45829

Presumably this should be an external redirect, not a URL rewrite, as your question suggests? To redirect from the old URL to the new URL?

For example, at the top of your .htaccess file in the document root, try the following using mod_rewrite:

RewriteEngine On
RewriteRule ^tags/([\w-]+)\.html$ /tags/$1/ [R=302,L]

Change the 302 (temporary) status to 301 (if that is the intention) only once you have confirmed this is working.

This assumes your TAGNAME consists of only the characters a-z, A-Z, 0-9, _, -.

Alternatively, if /tags is a physical directory then you could create a /tags/.htaccess file and use the following instead:

RewriteEngine On
RewriteRule ^([\w-]+)\.html$ /tags/$1/ [R=302,L]

Upvotes: 1

fabrik
fabrik

Reputation: 14365

This should do the trick:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)\.html$ /$1

Upvotes: 0

Related Questions