biber Posted August 14, 2016 Share Posted August 14, 2016 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 More sharing options...
Webrocker Posted August 14, 2016 Share Posted August 14, 2016 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 1 Link to comment Share on other sites More sharing options...
Mike Rockett Posted August 14, 2016 Share Posted August 14, 2016 @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. 2 Link to comment Share on other sites More sharing options...
biber Posted August 14, 2016 Author Share Posted August 14, 2016 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 More sharing options...
Webrocker Posted August 14, 2016 Share Posted August 14, 2016 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 1 Link to comment Share on other sites More sharing options...
biber Posted August 14, 2016 Author Share Posted August 14, 2016 @Webrocker Hi again, this hint brougt back my CSS and the pictures - thanx. Only the issue with the http://pw.bielenberg-soerup.de/center/gutschein.html - page remains, very strange. Günter Link to comment Share on other sites More sharing options...
Webrocker Posted August 14, 2016 Share Posted August 14, 2016 For me here your link works - no 404? I've had strange effects with .htaccess and local browser caching - make sure to flush all caches, or restart your browser and check again… cheers, Tom 1 Link to comment Share on other sites More sharing options...
biber Posted August 14, 2016 Author Share Posted August 14, 2016 Hi Tom, this tip saved my night! After flushing the Firefox-cache now everything works fine - thanx a lot Günter 1 Link to comment Share on other sites More sharing options...
Mike Rockett Posted August 15, 2016 Share Posted August 15, 2016 @biber - If you read my post again, you'll see that I mentioned that you need to place that line underneath the existing RewriteEngine on directive, not as the last rule. Nonetheless, what you have done is correct enough. Glad it works. 1 Link to comment Share on other sites More sharing options...
biber Posted August 15, 2016 Author Share Posted August 15, 2016 @Mike Rockett - You are right, being able to read is an advantage. 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now