berechar Posted July 19, 2016 Share Posted July 19, 2016 Hi all, I'm currently in the midst of making pages in PW which route the user to other directories and their index.html files (they are separately created and uploaded to the website). Instead of a redirect, I would like to keep the URL intact because it has valuable information for the PW tree. eg. PW Page (URL): site.local/project/33/essay Referred location (external directory, not part of PW): site.local/essays/33 Hopefully someone could give me some pointers on how to use the .htaccess file properly! Best, Charlie Link to comment Share on other sites More sharing options...
Macrura Posted July 20, 2016 Share Posted July 20, 2016 I would probably go with file_get_contents of the index.html files but you may also have to somehow account for asset locations, maybe with string replacements. Link to comment Share on other sites More sharing options...
berechar Posted July 20, 2016 Author Share Posted July 20, 2016 hmm, this approach seems to work, but is quite slow if I compare it by going to the actual page. Link to comment Share on other sites More sharing options...
Macrura Posted July 20, 2016 Share Posted July 20, 2016 right, you'd probably want to cache that markup for a certain time, like using wireCache otherwise, i'm not sure how else you'd get the contents of those files into PW pages, maybe ajax load, or iFrame are other options Link to comment Share on other sites More sharing options...
tpr Posted July 20, 2016 Share Posted July 20, 2016 If they are on the same server, you can try the P switch, eg. like this: RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^(www.)?oldsite.com$ RewriteRule ^(.*)$ http://newsite.com/$1 [P] Not sure if this will work, you would better consult a system administrator. 1 Link to comment Share on other sites More sharing options...
berechar Posted July 21, 2016 Author Share Posted July 21, 2016 Thanks, the page is on the same site. I came up with the following, but this seems to redirect me to the new URL (which is good), but doesn't save the originial URL (which is bad...) RewriteCond %{REQUEST_URI} !(^|/)project-[^/]+/([0-9]+)/essay$ RewriteRule ^project/([0-9]+)/essay$ /essays/$1 [P] Maybe the [P] flag isn't working? mod_rewrite is on... Link to comment Share on other sites More sharing options...
berechar Posted July 29, 2016 Author Share Posted July 29, 2016 Any PW System Administrators in town? I don't seem to get why the page is being forwarded. I'm quite convinced that it's the right pattern for the job... I tried some variations on the previous code, unfortunately without success RewriteCond %{REQUEST_URI} !(^|/)project-[^/]+/([0-9]+)/essay($|/.*$)$ RewriteRule ^project/([0-9]+)/essay($|/.*$)$ http://website.local/essays/$1 [NC,L] Link to comment Share on other sites More sharing options...
Can Posted July 30, 2016 Share Posted July 30, 2016 Maybe this helps # # check if file in /essays/ folder RewriteCond %{DOCUMENT_ROOT}/essays/$1/index.html -f # # serve static html version RewriteRule ^(.*) %{DOCUMENT_ROOT}/essays/$1/index.html [L,QSA] You probably need to adjust it a little, uh this expects your essays folder at your domain root (which seems to be from your main post?) Let me know if you get it working Link to comment Share on other sites More sharing options...
berechar Posted August 19, 2016 Author Share Posted August 19, 2016 Hi Can, Thanks for the reply. Yes, the essays folder is located next to the PW folders 'site' and 'wire'. Unfortunately, your rules result in a (default) blank page, which means that the condition wasn't met. I see in your RewriteRule that you're directly refering to an HTML page. I changed this in my original rule, and now the right page is being served! RewriteCond %{REQUEST_URI} !(^|/)project-[^/]+/([0-9]+)/essay($|/.*$)$ RewriteRule ^project/([0-9]+)/essay($|/.*$)$ http://website.local/essays/$1/index.html [NC,L] Unfortunately, all the resources referrals on this page (images, css, javascript) are now broken. It uses the new URL as the base. Can this be prevented? Link to comment Share on other sites More sharing options...
Mike Rockett Posted August 19, 2016 Share Posted August 19, 2016 @berechar - You'll need to refer to your site's assets relative to the root of your site, or absolutely where you include the domain explicitly. Link to comment Share on other sites More sharing options...
Can Posted August 19, 2016 Share Posted August 19, 2016 10 hours ago, berechar said: I see in your RewriteRule that you're directly refering to an HTML page. I changed this in my original rule, and now the right page is being served! what do you mean by directly? It's taking the requested url and checking if there is a index.html within the same path as the url I'm not the rewrite pro, more trial and error style My rewrite checks if the file exists, if not it won't rewrite and I'm having the "-f" flag appended to make sure there is an actual file in that path 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