Jump to content

Recommended Posts

Posted

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

Posted

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.

Posted

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

Posted

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.

  • Like 1
Posted

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...

  • 2 weeks later...
Posted

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]

 

 

Posted

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

  • 3 weeks later...
Posted

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?

 

Posted
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 

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
  • Recently Browsing   0 members

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