Dave Damage Posted January 22, 2015 Share Posted January 22, 2015 Hi folks, I'm in the final stage of importing a Wordpress Blog to processwire, and everything works just fine but the URL Redirects. I have installed the »Page Path History«-Module and during the import I insert the old Wordpress Path along with the new Post ID into the Module's Database. But when I try to access the page via "http://example.com/?p=13" it does not redirect me to the actual post but the Home-Page of my processwire installation. Figuring it has something to do with processwire's own Rewrite Rules in the .htaccess, I then had the idea to convert "/?p=13" to "/redirect/13/" and let the Page Path History -Module the rest. So in my .htaccess I created the RewriteRule: RewriteRule \?p=([0-9]+)$ /rewrite/$1 [L,R=301] But somehow this did not work, and every time I try to access "http://example.com/?p=13", I'm still being redirected to the Home-Page. So maybe one of you has some experience to handle such a problem or could point me in the right direction. Thanks in advance... Link to comment Share on other sites More sharing options...
adrian Posted January 22, 2015 Share Posted January 22, 2015 I am not sure on this, but I wonder if Page Path History can handle that URL format? Have you thought about using the Redirects module (http://modules.processwire.com/modules/process-redirects/) or the new Advance Redirects / Jumplinks (https://processwire.com/talk/topic/8697-alpha-processadvancedredirects/). I am also curious how you did your import. I am thinking of adding redirect support to the MigratorWordpress module (https://github.com/NicoKnoll/MigratorWordpress) and will probably use one of those two modules to do it. I would want to add both the ID based and SEO friendly WP links as redirects - any thoughts? 1 Link to comment Share on other sites More sharing options...
Dave Damage Posted January 22, 2015 Author Share Posted January 22, 2015 My thoughts exactly, so I thought it would be a good idea to let .htacess rewrite any url with "/?p=$wp-id" to "/rewrite/$wp-id". I had planned to insert into the Page Path History-Database "/rewrite/$wp-id" and the corresponding "processwire-pageid" in the hope that the module could handle that URL format. Since I expect an overhaul on many posts in processwire, especially regarding the Page-Names and thus the Page-Urls, it would be interesting if and how the "Redirects"-Module or the new "Advance Redirects/Jumplinks" work with "Page Path History". But I will have definitely a look into both Modules and playing around. Due to the bilingual nature of the Wordpress and the used Language Module (q-translate *grmblxfix*), I was unable to use the MigratorWordpress-Module, because the Language Module only allowed exporting into one language. Using https://processwire.com/talk/topic/3987-cmscritic-development-case-study/ , I wrote my own module (which proved to be quite cool, since I learned a lot about Processwire) and like I said, everything works as it should. (But I'm still quite unsure about best practices, though)... For the Wordpress-Urls, I simply extracted them from the database, used Regular Expressions to clean them up a little (removed the Toplevel Domain, so that only "/?p=$wp_id" remained) and during the page creation process, I inserted them via MySQL into the Page History Module Database. protected function updateGUID($id, $guid) { $current = time(); $db = $this->dbConnector('dbuser', 'dbpasswd', 'localhost', 'database_name'); $sql = "INSERT INTO page_path_history (path, pages_id, created) VALUES(:path, :pages_id, :created)"; $query = $db->prepare($sql); $query->bindParam(':path', $guid); $query->bindParam(':pages_id', $id); $query->bindParam(':created', $current); $query->execute(); } Another thing that still bugs me, that although $current has the correct timestamp, any insert into the database results in a timestamp of (0000-00-00 00:00:00) but if I leave the field blank, the $query won't execute... 2 Link to comment Share on other sites More sharing options...
Mike Rockett Posted January 22, 2015 Share Posted January 22, 2015 Per Ivan's comment below, this will not work because PW won't throw a 404 for the root of the site - this was an oversight on my part, and I do apologise for that. As stated, I'll try and implement this when I rewrite the module. As an alternative, see my post below. Hi Dave Regarding Jumplinks, it would definitely come in handy - though I haven't release a final 1.0 yet. (Next few days, hopefully.) (Also, not compatible with 2.5.3.) You'd basically create a new redirect like so: Source: ?p={id} Destination: rewrite/{id} There's also the alternative, where you can map IDs to URIs (names) using mapping collections. You'd need to export your URIs from WordPress in the format below (one on each line) into to a mapping collection called, say, "wordpress". id=path Example: 1892=this-is-an-awesome-post Your redirect would then look like this: Source: ?p={id} Destination: posts/{id|wordpress} If a source pattern is hit, then it'll check the collection according to the ID provided, and replace it with the new name (posts/this-is-an-awesome-post, in this case). 2 Link to comment Share on other sites More sharing options...
Dave Damage Posted January 22, 2015 Author Share Posted January 22, 2015 (edited) Hi Mike, Jumplinks sounds exactly what I need, especially the mapping collections. I'll try it out right now. Edited January 22, 2015 by Dave Damage 1 Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted June 19, 2015 Share Posted June 19, 2015 @Mike: Can't get your solution to work. The other redirects are running as they should, but this one does not even trigger the module (I turned the debug mode on). Tried it on localhost in subfolder and on a subdomain on a live server if that matters. Link to comment Share on other sites More sharing options...
Mike Rockett Posted June 19, 2015 Share Posted June 19, 2015 @Mike: Can't get your solution to work. The other redirects are running as they should, but this one does not even trigger the module (I turned the debug mode on). Tried it on localhost in subfolder and on a subdomain on a live server if that matters. Ah, that is indeed a bad assumption on my part. Because the REQUEST_URI in this case is for the root, PW will not return a 404, and thus Jumplinks won't come into effect. Unfortunately, this is the caveat of hooking to the 404 event. I will look into this when I rewrite the module. As a suggestion, and if you're using mapping collections, you can add the following to your condition and rule to .htaccess (right at the beginning to be safe): RewriteCond %{QUERY_STRING} ^p=(\d+)$ RewriteRule ^$ /postid_querystring?p=%1 [R=302,L] Then you can create a jumplink with postid_querystring?p={id} as the source. (Not tested, but it should work.) 1 Link to comment Share on other sites More sharing options...
Sergio Posted June 19, 2015 Share Posted June 19, 2015 Hi Dave! I'm almost on the same situation, a Wordpress site using the qtranslate plugin. Would you mind sharing your import module so I can take a look how you did it? 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