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

Installed Wordpress in my YoURLS directory... now what? Excluding /blog/ somehow? #2108

Closed
jonathanalevi opened this issue Jun 13, 2016 · 16 comments

Comments

@jonathanalevi
Copy link

Technical details

  • YOURLS version: 1.7.1
  • PHP version: 5.2.17

Reproducible Bug Summary

  1. I have had YoURLS in the root directory of http://jle.vi for years - works great, I can't live without it.
  2. Recently, I decided to migrate the website to Wordpress so I can create a blog. I don't care if the posts are short-linked through wordpress... the permalinks can be at http://jle.vi/blog/whatever-name-doesn't-matter or something
  3. Currently, YoURLS is dominating the .htaccess, so I guess Wordpress can't make redirects. So, I can't get to posts.

This is a bug because I need to be able to link to blog posts, even if they aren't permalinks. It would be best if they were, and I could just exclude the /blog/ from rewrites, but I don't know how to do it.

I'm a pretty big novice, so I appreciate your patient and thorough explanation of what I need to do (for example, change a setting in Wordpress, add something to .htaccess, etc).

I don't want to move YoURLS, and obviously cannot move the entire site, unless, I guess, I redirect http://jle.vi/ to http://jle.vi/site or something like that and move the entire wordpress install.

Anyways, I attached the .htaccess file. Thanks for your help, everyone.
htaccess.txt

@ozh
Copy link
Member

ozh commented Jun 13, 2016

It should work just with installing WP as usual in a subdirectory, ie :

  • YOURLS in [root]
  • [root]/.htaccess with YOURLS directive
  • WP in [root]/blog
  • [root]/blog/.htaccess generated by WP

@jonathanalevi
Copy link
Author

@ozh I want the website itself to remain in http://jle.vi, as it is now, just the blog posts to go to /blog/.

Do you know how I could possibly do this? Do I need to relocate the whole installation in order to do it and do some kind of redirect from root of jle.vi to jle.vi/blog or something? I wouldn't want the /blog/ in the URL for the main webpage, but if I had to, I'd live with it...

Thanks
JL

@ozh
Copy link
Member

ozh commented Jun 15, 2016

You just need to do just as I said above

@ozh ozh closed this as completed Jun 15, 2016
@jonathanalevi
Copy link
Author

jonathanalevi commented Jun 21, 2016

Actually, this doesn't answer my question, because I still want the site to be hosted at jle.vi/, not jle.vi/site. I don't mind the BLOG posts to be at /site/, but the main site, I want to be at http://jle.vi/

If I do as you said, "[root]/.htaccess with YOURLS directive", then the whole site operates at jle.vi, and I don't know what happens when someone just goes to jle.vi without /site/ - know what I mean?

Should I maybe post in the wordpress help forums...?

@phy25
Copy link

phy25 commented Jun 21, 2016

Your blog/... thing confused us at all, because what you are actually doing is: installing WordPress and YOURLS in the same directory. So you are trying to let them work at the same time.

I don't think you should ask here (maybe stackoverflow is better), NEITHER THIS IS A BUG. Just remember, WordPress doesn't have single post links only, it also have categories, tags, wp-json, feed and a lot more. But let's assume you just want blog/... work. You need some knowledge of regex.

# BEGIN YOURLS
<IfModule mod_rewrite.c>
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index\.php$ - [L]
RewriteRule ^(?<!blog)(.*)$ /yourls-loader.php [L]
</IfModule>
# END YOURLS

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

It may not work, and I don't recommend this practice.

@ozh
Copy link
Member

ozh commented Jun 21, 2016

@phy25's solution won't work. You cannot have YOURLS and WP installed in the same directory.

@entreprenewer I don't understand what you mean with "site", "blog", "main site", "whole site". I just don't understand what you're trying to achieve.

@jonathanalevi
Copy link
Author

Let me try to explain as clearly as I can.

I want my website to function at http://jle.vi - without any additional subdirectory in the URL (such as /blog/ or /site/)

However, in order to be useful, YoURLS needs to be installed in that root directory. I have thousands of links in there, and I'm not about to change them, plus, jle.vi/s/link is not a very useful short link, now is it?

Right now, Wordpress is in the same directory as YoURLS... and it's working. But only because http://jle.vi is a one-page theme.

As soon as I try to add the "blog" functionality of the theme, which links to other subdirectories (permalinks), then stuff breaks.

I don't mind if all permalinks at at http://jle.vi/blog/link-name-here or something.. but as far as I understand it, if I move the Wordpress installation in it's entirety to http://jle.vi/blog/ or any other URL, then the site won't load when people go to http://jle.vi

I guess part of what I'm asking is what happens if you JUST have YoURLS in a directory? What happens if people go to the root URL? What would happen if wordpress wasn't in there? I guess I would have to redirect to a subdirectory?

@ozh
Copy link
Member

ozh commented Jun 22, 2016

Well, you already have the 2 answers to your problem:

  • you cannot have YOURLS and WP installed in the same directory.
  • see my comment about having YOURLS in root and WP in /blog/

@TuKod
Copy link

TuKod commented Feb 21, 2017

@ozh your above statement...

You cannot have YOURLS and WP installed in the same directory.

Makes me wonder? I have an apache server with 65 WordPress domains across 8 multisite WP installs, all centered on one document root (directory). In addition, there was some hand coded websites and a couple forums, often sharing the same domain name and/or the same directory (URI) structure.

Don't ask me why (started way back in 19-forgotten, before Google!). The point is that it worked by identifying the URI/directory structure differences. It seems to me it would be a simple thing to do the same with WordPress and YOURLS. In other words, I see no conflict with running the following together:

http://vekind.org/ (WP - domain default page)
http://vekind.org/vekind-basics/ (WP - page)
http://vekind.org/welcome-terrans/ (WP - post)
http://vekind.org/topic/vekind/earthling/ (WP - category page)

and something like...
http://vekind.org/v7hsLAN (YOURLS redirect URL)

This should be quite easy to do in Apache (and is what I am working on in Nginx).

If you would like, I could load a basic site with WordPress and YOURLS in Apache and write some simple directions on how to run them both in the same document root. Perhaps just a slight change.

If you think it would help others.

Sincerely,

Lan

PS: I would also suggest giving YOURLS its own directory, configurable like WP does. This may allow more WP compatibility and make YOURLS multisite easier.

@ozh
Copy link
Member

ozh commented Feb 25, 2017

WP's .htaccess : "when a file requested isn't a real file on the server (eg a .CSS or a .GIF) then redirect to index.php"
YOURLS' .htaccess : "when a file requested isn't a real file on the server, then redirect to yourls-loader.php"

So, basically, you cannot have WP and YOURLS in the same directory because they work the same way and then your htaccess would need to redirect to something that would first have to guess if a requested URL is a WP thing or YOURLS stuff.

@TuKod
Copy link

TuKod commented Feb 26, 2017

Yes, I agree with what you said about WP and YOURLS. However, that works in our favor. All one would need to do is to make a simple .htaccess file that would serve both programs.

.htaccess has both regex and conditional statements. Just a quick overview of the way WP and YOURLS really works leads me to think there are many different regex that could be simply written to exploit the differences. All that we would need to do is find one thing that one program always does that the other didn't do and bingo...

if (condition) {do index.php) else {do yourls-loader.php}.

Just write that logic into .htaccess.

Tell you what, I am traveling this week, but when I get back to the office next week, I will write the ,htaccess file for you. Do you want it for a single WP site with a Single Domain YOURLS, or a multisite WP?

I will show you how easy it is to have YOURLS play nice with WP.

Regards,

Lan

@ozh
Copy link
Member

ozh commented Feb 26, 2017

I am fully aware of how this can be done. You'll find several explanations in issues here or even "tutorials" on the web of people who needed it and toyed with the idea. This is just something I don't want to support because it has to be tailor made depending on each setup (ie your "if (condition)" will vary, some folks will restrict YOURLS URLs to 5 chars to segregate them from WP, others will do something else, and so on) and doesn't rely on YOURLS only.

Anyway your solution to this problem is welcome as it may help searching for the same issue. Feel free to post your solution in a separate issue and answer it, Q&A style.

@TuKod
Copy link

TuKod commented Mar 1, 2017

Yes, I see your point.

Basically, for a guy like me, who has been programming since back to the days of ARPANET at DARPA, "easy" is a relative term. I agree that ANY .htaccess setup needs to be extremely clear, similar to what WP or YOURLS now uses.

Sort of "copy, paste, and change this to that!" (Like "Change example.com to your domain name.")

"Restrict YOURLS URLs to 5 chars to segregate them from WP"

That's an interesting idea I hadn't thought about. However, immediately I can see some serious flaws in this reasoning.

1. You'd run out of URL's before you reached a billion (a billion is really not that many if the site is open to the public).

2. I maintain a few hundred sites that have either "home" or "about" pages, or both. My guess is that those pages, or any other with a URI <6, would be sent to YOURLS (and crash in WordPress). A "five or less chars" limit might work for one guy publishing a single blog, but enforcing a greater than 5 chars WP rule on dozens (or thousands) of people will surely result in problems for some WP pages.

3. One additional problem I see is that a result of using WP in Multisite mode. So example.com, example.net, and example.org are going to be mapped to one single directory. Therefore, to a single .htaccess file. Assume YOURLS was only for the example.org domain, this five chars limit would send YOURLS some traffic (in error) from example.com and example.net also.

I agree with you that this needs to be something simple, very simple, "copy paste simple!" I will work on a solution toward that end.

I have two questions I did not see on your FAQs or that I want to make clear.

  1. Am I correct that YOURLS is always used on one domain only? Meaning that one set of files is used to support YOURLS on one domain name?

  2. Do you have a list of links to unsupported "tutorials" or unsupported third party advanced YOURLS configurations that people have posted? It would save time seeing what other people have examined or tried.

Regards and Thanks,

Lan

@ozh
Copy link
Member

ozh commented Mar 2, 2017

Answers:

  1. out of the box, yes, one set of files for one location. This said, I think there's a plugin or a hack somewhere to have multi domain support.
  2. Nope. Everything noteworthy we've found is either mentioned in the readme or sometimes in specific issues here

@TuKod
Copy link

TuKod commented Mar 3, 2017

Thanks ozh, your answers are very clear and specific - great support!

1) Give YOURLS Its Own Directory
I currently have a hack on my development server that gives YOURLS its own directory with just a configuration. In other words, out of the box, it works the same, but adding one configuration line and you can put the YOURLS files anywhere (any directory) you want and let it still work from the root directory.

2) YOURLS and WordPress Sharing the Root Directory
This is under test with 36 and 62 versions, with no restrictions to YOURLS. The setup is only simple configuration and giving YOURLS its own directory (above). The WP setup has one Pretty Permalinks setup restriction, but most people would not use that anyway.

3) YOURLS and WordPress Multisite Sharing the Root Directory
One of my advanced students is testing the number 2 settings above with a WordPress Multisite with the Multi-Networks plugin activated ( different domain names like VeKind.org and Plant-Only.org ). This would result in YOURLS (one domain) being on the same rood directory as WP Multisite (our test platform has 45 domains). The setup requires the YOURLS domain be listed in the .htaccess file, but is still very easy to understand.

4) YOURLS Multisite
I have a roadmap to allow advanced users to define constants in the config.php file to enable multisite (multidomain) handling based on different domains, all via one root directory. Also compatible with all the above configurations.

Each of these configurations is simple and easy to do at a novice or beginner's level.

I will move this to my Lan Net Work site so my students can have a go at it, and test it. Will start a new thread with the finished hack or if we have any further questions.

Thanks again for your great support Ozh!

Best Regards,

Lan

@magcrider
Copy link

You cannot, I tried different ways, maybe with new apache 2.4 using the if else statement you will, but I am not an expert on those commands, I want to share what I did to have the shortener option in the root page and the html site in a subdirectory, with this solution you can still give people normal url for the website (e.g. sho.rt):

set your website in a folder under root with a name e.g. "w", that means it will be at "sho.rt/w"

then use this .htaccess

# BEGIN YOURLS
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^.*$ /yourls-loader.php [L]
    RewriteRule ^$ /w [L]  
</IfModule>
# END YOURLS

This will give you the option to still use sho.rt as your website address if the user doesn't pass any subfolder in the url, but if they do, it will check in yourls first and go to your folders if nothing found.

One more thing, do not forget to add "w" in the $yourls_reserved_URL array in /user/config.php (Yourls config file)

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

5 participants