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

Basic Installation Using Provided Instructions Results in 403 Error #14

Open
Bukijon opened this issue Jan 6, 2021 · 4 comments
Open

Comments

@Bukijon
Copy link

Bukijon commented Jan 6, 2021

@gerbz
Hi There,

This plugin describes exactly what we would like to do, but we are having issues getting its basic functionality going.
Here is what we are doing step-by-step. If you or someone here could help point me in the right direction, that would be awesome.

Our goals:

  1. Install shortened urls at https://localhost/redirects/.
  2. Administer shortened urls at https://localhost/redirects/admin/index.php.
  3. Have our short base url be https://localhost. Example short url https://localhost/page1
  4. Then redirect to our longurl.

Here are the specs of our setup:

Apache - php 7.3 or 7.4 (same setup on both with same results)
MySQL - 5.7.30

Entire installation is completely fresh. No additional plugins are activated except for swap-short-url.

.htaccess files:

Installation .htaccess file (generated automatically upon installation) is located in --> https://localhost/redirects/.htaccess
It contains the following directives:

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

.htaccess file in the domain root is located at --> https://localhost/.htaccess
it contains the directives specified in the swap-short-url installation read-me file and is noted below:

RewriteBase /
# BEGIN YOURLS

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([0-9A-Za-z]+)/?$ https://localhost/redirects/yourls-go.php?id=$1 [L]
RewriteRule ^([0-9A-Za-z]+)\+/?$ https://localhost/redirects/yourls-infos.php?id=$1 [L]
RewriteRule ^([0-9A-Za-z]+)\+all/?$ https://localhost/redirects/yourls-infos.php?id=$1&all=1 [L]
# END YOURLS

config.php adjustment

config.php file in installation directory is located at --> https://localhost/redirects/user/config.php

/*
** Personal settings would go after here.
*/
define( 'YOURLS_SHORT_URL', 'https://localhost' );

RESULTS

Everything appears as it should, but does not result in a successful redirect.
In the admin area, short urls are successfully defined with the following format
https://localhost/shorturl1
https://localhost/shorturl2
and so on...

When the shortened URL is entered into the browser, the redirect starts to happen, but stops at the base url...
https://localhost/redirects/
and a 403 Forbidden error is returned. (see screenshot)
403-error-swap-short-url

Any help/guidance you can provide would be very helpful.

Thanks,
-Buki

@Bukijon Bukijon changed the title Basic Installation Using Provided Instructions Results in 403 or 404 errors Basic Installation Using Provided Instructions Results in 403 Error Jan 6, 2021
@Bukijon
Copy link
Author

Bukijon commented Jan 9, 2021

@gerbz - just wanted to add that I have checked permissions of files/folders as well and they all seem to be set as they should be. So I'm unsure why I'm receiving a 403.

Thanks,

-Buki

@DustyClaus
Copy link

DustyClaus commented Jan 30, 2021

Same issue. Solved by replacing the three RewriteRules with just this one:

RewriteRule ^([-0-9A-Za-z]+(+(all)?)?~?)/?$ http://shorturl.com/yourls/$1 [L]

It has been suggested in another post here. Hope it helps someone else just as it helped me.

@golddave
Copy link

golddave commented Oct 8, 2021

I'm currently experiencing this 403 error and the suggested RewriteRule change caused a 500. Any other thoughts?

@scottruzal
Copy link

scottruzal commented Jan 11, 2022

I'm currently experiencing this 403 error and the suggested RewriteRule change caused a 500. Any other thoughts?

This is what did it for me. I have my Yourls installation on a subdomain (i.e. https://link.doma.in) and wanted to redirect all shortened links to work with just the base URL (i.e. https://doma.in/shortcode). I set up my short domain as a subdomain on another domain (i.e. doma.in.otherdomain.com) where my base short domain A record points to (i.e. https://doma.in redirects to https://otherdomain.com). I set up a separate .htaccess file in the new subdomain directory with the following instructions:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([0-9A-Za-z]+)/?$ https://link.doma.in/$1 [L]
RewriteRule ^([0-9A-Za-z]+)\+/?$ https://link.doma.in/$1 [L]
RewriteRule ^([0-9A-Za-z]+)\+all/?$ https://link.doma.in/$1&all=1 [L]

My use case was very specific (I wanted to be able to use my domain for both short URLs, have the base URL redirect to my personal website, and use my web host email with my shortdomain), but this solution ended up checking all of the boxes for me.

Based on your setup, you may find similar success with the above rewrite rules, which are a variation on the original installation instructions and slightly differ from the suggestion above.

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

4 participants