Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

301 redirects in htaccess #147

Open
wesort opened this issue Apr 29, 2016 · 8 comments
Open

301 redirects in htaccess #147

wesort opened this issue Apr 29, 2016 · 8 comments

Comments

@wesort
Copy link

wesort commented Apr 29, 2016

I'm working through some changes on a Stacey site and am wondering how to best handle URL redirects. My use-case is for maintaining legacy URLs for both user convenience and SEO.

Example:
/projects/old-url should redirect to /projects/new-url

I have the following in the root .htaccess file
redirect 301 /projects/old-url/ http://example.om/projects/new-url/
NB "RewriteEngine on" already, domain changed for client privacy

The /new-url page loads as follows:

  • Correct: page content as expected from the yml file
  • Incorrect: URL includes the original URL as a query string http://example.com/projects/new-url/?/projects/old-url/
  • Incorrect: Images are not displayed http://example.com/projects/new-url/content/1.projects/new-url/image.jpg

Any ideas how to resolve this? Or is this simply how Stacey operates and therefore unavoidable?

@wesort
Copy link
Author

wesort commented Apr 29, 2016

FYI: Workaround

  1. Create a directory in /content/projects and name it old-url
  2. In the .yml content file within that new directory, add a php redirect

Example

<?php
header("Location: http://example.com/projects/new-url", true, 301);
exit();
?>

Where the workaround is lacking
This is not ideal as it's a laborious process to create the extra directories and content files and by this measure somewhat unworkable in the long run compared to a standard list of 301 redirects in a .htaccess file.

@pbatts
Copy link

pbatts commented Apr 29, 2016

What version of Stacey are you using?

@wesort
Copy link
Author

wesort commented Apr 29, 2016

3.0.0 according to line 5 of stacey.inc.php in the app directory.

FYI: I picked up this project as a reskin. It was set-up by someone else (who I don't know) a few years ago.

@pbatts
Copy link

pbatts commented Apr 29, 2016

It sounds like you are not using the most recent htaccess file. Or your htaccess file is corrupt.
https://github.com/kolber/stacey/blob/master/htaccess

Also chmod 777 app/_cache

I am assuming the "example.om" in your example above is a typo and not what is actually being used.

@wesort
Copy link
Author

wesort commented Apr 30, 2016

Thanks, but still not resolved.

This is after replacing my .htaccess and running chmod 777 app/_cache (and even ran chmod -R 777 app/_cache to be sure.) And yup, example.om was a typo when I removed the client url.

Can I ask, do you have 301 redirects working on any other Stacey sites?

@pbatts
Copy link

pbatts commented Apr 30, 2016

I do not have any 301 redirects on any Stacey sites.

I just tested this on one of my Stacey sites and got a 404.

I have not had a need for 301 redirects on any Stacey sites, but, now you have me curious. Please keep us updated on what you come up with.

@wesort
Copy link
Author

wesort commented Apr 30, 2016

Well thanks for trying anyway.

As I needed to push content changes live, which included renaming some projects, I have used the workaround mentioned above of php redirects. A little bit laborious as there were 30 or so redirects needed, but used a spreadsheet to concatenate the php snippets. If I was better at bash I'm sure a script could be made easily enough.

@pbatts
Copy link

pbatts commented Apr 30, 2016

Sorry I couldn't be more help.

I am not very good with php but I suspect the problem/answer is in app/stacey.inc.php at lines 11-13 and 18-20.

if(preg_match('/^\/?(index|app)\/?$/', $_SERVER['REQUEST_URI'])) {
  header('HTTP/1.1 301 Moved Permanently');
  header('Location: ../');

header('HTTP/1.1 301 Moved Permanently');
  header('Location:'.$_SERVER['REQUEST_URI'].'/');
  return true;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants