Rewrite url using regex in apache

I have just moved a site from IIS to Apache and from asp to PHP however I don’t want to have dead links all over the place I been reading about rewriting with regex but have not been able to make it work basically I had URLs that looked like this

and now they are like this

I have this so far but it does not work

RewriteRule ^artman2/publish/([a-z]+) /([a-z]+)\.asp$

this part is always the same

and this part always changes /The-coming-fall-season/For-Fox-a-newfound-stability-this-fall.asp

any help is appreciated


Have you read the tutorial linked in my signature? There are two bits of sample code which would help, the first in defining character ranges and the second if replacing file extensions. To make a long story short, all you need is:

# .htaccess in DocumentRoot

RewriteEngine on

# Replace extension for directory/filename in artman2/publish directory
# Note: Apache 2.x assumed
RewriteRule ^artman2/publish/([-a-zA-Z]+)/([-a-zA-Z]+)\\.asp$ artman2/publish/$1/$2.php [R=301,L]

What you were missing was the leading - and uppercase characters in the character range definitions (and a redirection in your RewriteRule).

You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It’s helped may members and should help you, too.



I tried your rewrite and went through the link in your signature and still can’t get it to work, I modified the rewrite you gave me as the structure is different but even trying yours the url does not change this is all I have right now in the htaccess file

RewriteEngine On
RewriteBase /
RewriteRule ^artman2/publish/([-a-zA-Z]+)/([-a-zA-Z]+)\.asp$ index.php/$2/ [R=301,L]

why would it not follow the rewrites?

Now I feel a little retarded, I guess I need to sleep a little more, I did not uncommented mod_rewrite, although reading that post in your signature did help and also the rewrite rule you helped me construct, thank you