Changing a script - permanent redirection question

by 9 replies
12
Hi ..

I'm about to change the script which is running one of my oldest websites ..
I need to make a permanent redirection for about 300 pages (articles) ..

The old URLs are like
www.site.com/example-1/article-title-here.htm

with the new script installed , I would like all the URLs in that format to be redirected to
www.site.com/example-2/article-title-here

How can I do that ???

Will be thankful
#programming #changing #permanent #question #redirection #script
  • Put the following into your website's root .htaccess file:

    Code:
    RewriteEngine on
    RewriteBase /
    RewriteRule ^example-1/([0-9A-Za-z\-]+).htm$ example-2/$1 [R=301,L,QSA]
    • [ 1 ] Thanks
    • [1] reply
    • You left a number of allowed characters out of your regex. It's probably better to let everything through since the rewrite's job is not to filter URIs, but to rewrite/redirect:
      Code:
      RewriteEngine on
      RewriteBase /
      RewriteRule ^example-1/(.+).htm$ example-2/$1 [R=301,L,QSA]
      • [ 1 ] Thanks
      • [1] reply
  • Is this to rewrite or to redirect ?
    • [1] reply
    • It redirects. Notice the R=301 in the [flags] area. This tells Apache to tell the requesting browser that the page has moved permanently and to request the new address.
      • [ 1 ] Thanks

Next Topics on Trending Feed