mikecao / shorty

A simple URL shortener for PHP
MIT License
271 stars 98 forks source link

404 when going onto shortened URLs #9

Open Shoot opened 6 years ago

Shoot commented 6 years ago

Set everything up following the guide, .htaccess, confs for the domain etc all done, database sorted. When I try to add a URL it generates, but when I click on the URL it doesn't work, instead giving a 404 message.

lfdelphino commented 6 years ago

Hey @old , I was experiencing the same issue and I could fix it.

There are a few things that may be causing it, first of all, are you trying to use a different URL to shorten your links or the default index.php? If it's the default shouldn't be a problem.

Second, make sure that you run the following SQL command on your MySQL or MariaDB: CREATE TABLE urls ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, url VARCHAR(1000) NOT NULL, created DATETIME NOT NULL, accessed DATETIME, hits INT UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (id), UNIQUE (url) );

I was using a different SQL code that I found by mistake and also my goal was to be able to shorten the URL at a different location, to do so you would only have to change on .htaccess from: RewriteRule ^(.*)$ index.php?q=$1 [QSA,L] to (change the NEW_URL): RewriteRule ^(.*)$ https://%{HTTP_HOST}/NEW_URL.php?q=$1 [QSA,L]

Hope it works!

Nottt commented 5 years ago

I'm having the same issue, but the above solution didn't help me! Running the sql command just says:

ERROR 1050 (42S01): Table 'urls' already exists
lfdelphino commented 5 years ago

First remove your table urls, then run the above SQL please

Nottt commented 5 years ago

My website domain is subdomain.domain.com, and I'm generating subdomain.domain.com/link/XXX o i still need to use your SQL command?

I'm a bit lost here, ideally I'd like to use another domain, a shorter one in the generated links... like xx..cc which I own, I'm just using that for testing...

Do I need to have my xx.cc domain pointed to the same IP address as my subdomain.domain.com? Do I need to change something in apache?

My shorty files are in /var/www/html/link so that's why i went with that for testing...

Nottt commented 5 years ago

ok, so my issue seems that going to xx.cc redirects to subdomain.domain.com/XXX and this doesn't work but subdomain.domain.com/link/XXX works.

How to fix this?

Edit:

I fixed this with a cloudflare rule, I now forward xx.cc/* to subdomain.domain.com/link/ so it works. I'm doing 2 redirects to get to the shortened link but at least works.

A solution which only does 1 redirect locally would be better/faster