Jump to content

htaccess: go to another directory, but keep the (PW) URL


berechar
 Share

Recommended Posts

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

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
Link to comment
Share on other sites

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

  • 2 weeks later...

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

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

  • 3 weeks later...

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

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

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