Syed Ahmed
Syed Ahmed

Reputation: 1645

htaccess regex redirect

I am trying to redirect from source url to target url using regex but it didn't work. Here i describe my problem -

Source URL:

http://example.com/forums/forum/lisa-goran-bygger-hus-t5075/

Target URL:

http://example.com/forums/details/lisa-goran-bygger-hus/

want to redirect without -t5075 from url.

htaccess rewrite rule is:

RewriteRule ^/forums/forum/([a-z-]+[^-t0-9]) /forums/details/$1 [R=301,L]

this isn't work its redirect to me -

http://example.com/forums/details/lisa-goran-bygger-hus-t5075/

Here regex online tester link -

http://www.regextester.com/?fam=97698

What i am doing wrong can someone help me out and explain about this problem.

Thanks

Upvotes: 0

Views: 114

Answers (1)

Justin Iurman
Justin Iurman

Reputation: 19026

First, make sure mod_rewrite is enabled and htaccess files allowed to be executed.

Then, make sure .htaccess file is in root folder and look like this

RewriteEngine On
RewriteRule ^forums/forum/(.+)-t[0-9]+/$ /forums/details/$1/ [R=301,L]

Finally, try clearing your browser's cache. Indeed, your old rules could interfere. After that, it should work.

Upvotes: 1

Related Questions