1

[Edit to be a little clearer:]

I have a project hosted on Google App Engine (myappname.appspot.com)/ (myappname.com). So far so good.

There's a root level, and a subdirectory called folder. The css styles for that subdirectory are in folder/css. (e.g. folder/css/main.css).

When I request myappname.com/folder/, the content loads correctly, including css styles. Note the trailing slash /.

However, when I go to myappname.com/folder (no trailing slash), no css is loaded. I see in my logs a request for css/main.css, which does not exist. What's going wrong and how can I fix it?

Here's the relative link from index.php:

<link rel="stylesheet" href="css/main.css">

Here's my app.yaml:

application: myappname
version: 1
runtime: php
api_version: 1

handlers:

- url: /folder/css
  static_dir: folder/css

- url: /folder/
  script: folder/index.php

- url: /folder
  script: folder/index.php

- url: /.*
  script: index.php

Thanks!

Lisa Wray
  • 2,242
  • 16
  • 23

2 Answers2

1

As per your edit - this should work:

<link rel="stylesheet" href="/myappname.com/folder/css/main.css">

Just fill in myappname.com with whatever yours is.


Or you could use app.yaml and add the following:

- url: /css
  static_dir: css/folder

Then change your link to:

<link rel="stylesheet" href="/css/main.css">
abagshaw
  • 6,162
  • 4
  • 38
  • 76
  • Well, technically, yes. :) But there's a reason relative links exist. What if I change the directory structure later? What if I host somewhere else? I am really looking for an answer about why relative linking is working correctly in one case, and incorrectly in the other. – Lisa Wray Apr 09 '15 at 02:05
  • Hi abagshaw, Thanks for the edit. Yes, this redirects correctly. But it assumes I do not have other subdirectories. – Lisa Wray Apr 09 '15 at 20:03
  • You mean other sub directories other than folder? Or sub directories past folder (i.e. `folder/afterfolder/afterafterfolder`)? – abagshaw Apr 09 '15 at 20:07
0

To fix the problem hardlink your stylesheet, like this:

<link rel="stylesheet" href="/css/main.css">
Katherine
  • 639
  • 5
  • 16
  • Hey @Bill, unfortunately that makes the page load without the stylesheet in both situations. I looked in the logs and as you would think, hard linking to /css/main.css tries to load a file located at /css. It is actually in /folder/css/main.css. The problem is, I can't figure out why requesting "folder/" successfully requests /folder/css/main.css yet "folder" requests the non-existent /css/main.css. – Lisa Wray Apr 09 '15 at 00:32
  • Can you link to /folder/css/main.css? Otherwise, another option is to use htaccess (or similar) to add trailing slashes to all pages. – Katherine Apr 09 '15 at 00:34
  • If I hardlink to /folder/css/main.css, then requesting folder/ (trailing slash) fails because it tries to get folder/folder/css/main.css. – Lisa Wray Apr 09 '15 at 00:36
  • I didn't think GAE allowed .htaccess? Pretty sure all the rules need to be in app.yaml. I'm just a newbie at writing them. – Lisa Wray Apr 09 '15 at 00:38
  • You're right, I missed it. You can use app.yaml. This post explains it: http://blog.engelke.com/2008/07/31/appengine-rewrite-rules/ – Katherine Apr 09 '15 at 01:29