Jump to content

migrating a site with .htaccess


biber
 Share

Recommended Posts

I have to migrate a site to PW and want to take the visitors of my old site. The pages of the old site end with '.html', the ones of the new site with '/'. I dont want to use a workaround like renaming the pages to *.html or a redirect-module. I think it is a cleaner solution to set a permanent redirect in the .htaccess. So I added a line

  RedirectMatch 301 (.*)\.html$ http://pw.bielenberg-soerup.de$1/

to change 'pw.bielenberg-soerup.de/center/gutschein.html' to 'pw.bielenberg-soerup.de/center/gutschein/'

but this makes an adress  like

http://pw.bielenberg-soerup.de/center/gutschein/?it=center/gutschein.html

which leads to a 404-error. maybe there is the line

 RewriteRule ^(.*)$ index.php?it=$1 [L,QSA]

in the .htaccess which is responsible for this behavior, but I do not know enouth about that to understand.

Can someone help me to set the right option?

Link to comment
Share on other sites

Hi,

a bit difficult to say without seeing the complete .htaccess, but I think you need to add a "L" to the first rule.

RedirectMatch 301 (.*)\.html$ http://pw.bielenberg-soerup.de$1/ [L]

so if this rule is matched, no other redirects will happen afterwards. If you have querystrings, add [L,QSA] ("query string append") so that the new destination will receive the query parameters. And make sure that this rule is before the index.php rule which acts like a catch all -- everything (that hasn't been caught by other rules before) will be redirected to the index.php and the querystring is appended.

Basically what you are saying with that rule is: "everything that ends with ".html" will be taken to the new location and be appended there with a slash at the end.

Depending on your site/url structure this may be enough, or you need to add a more precice rule what to redirect.

cheers
Tom

  • Like 1
Link to comment
Share on other sites

@Webrocker - RedirectMatch does not support flags, so [L] will not work.

@biber - Please add the following under the existing RewriteEngine on directive:

RewriteRule ^(.+).html$ /$1/ [L]

Note that the QSA flag is not required here. Also note that I have added a trailing slash as that is the PW default. If you have removed trailing slashes on all your templates, then you can remove it here too, saving an additional redirect.

  • Like 2
Link to comment
Share on other sites

First thanks to you both for helping me.

@Mike Rockett - I had already figured out that mod_rewrite is active, so I added your recommendation to the last but one line of my .htaccess. For the most pages it works as desired, but some strange things happen:

-- If I view a page the first time after I have added the line, it is shown as desired, also the redirection of .html-pages works. But if I press F5 for reloading the page, the CSS is no longer present.

-- The page http://pw.bielenberg-soerup.de/center/gutschein.html leads to http://pw.bielenberg-soerup.de/center/gutschein/?it=center/gutschein.html what ends up to the 404-page. I cannot find anything different to all the other pages. If it could help I attach the .htaccess here.

.htaccess

Link to comment
Share on other sites

Hi again.

I think the problem is that you added the rules too late, somewhere down in the htaccess when PW is already involved. What you want is to catch the "wrong" requests as early as possible -- so add the rewrite rules for your old URL scheme at the beginning of the htaccess file:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^(.+).html$ /$1/ [L]
</IfModule>
#################################################################################################
# START PROCESSWIRE HTACCESS DIRECTIVES
...

cheers,
Tom

 

 

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...