My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
htaccess  
What your .htaccess file should look like
Featured, Phase-Deploy
Updated Aug 1, 2011 by ozh...@gmail.com

Make a .htaccess file

If .htaccess file creation/updating failed because of file permission, you'll have to manually make one. It's simple.

Case: YOURLS installed on root

If YOURLS root URL is http://yoursite/, the .htaccess file in the root directory must be like:

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

Case: YOURLS installed in subdirectory

If YOURLS root URL is http://yoursite/somedir/, the .htaccess file in this subdirectory must be like:

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

Bonus: Force non-WWW

Add this after the YOURLS block in your .htaccess file, replacing yourls.org with your own domain

# BEGIN WithoutWWW
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.yourls\.org$ [NC]
RewriteRule ^(.*)$ http://yourls.org/$1 [R=301,L]
# END WithoutWWW

This directive MAY or MAY NOT work on your host (ie http://sho.rt/stuff might work fine and http://www.sho.rt/stuff might not). If it doesn't work, simply stick to one domain, either with or without www. There is no real support for both www and non-www domain setup.

(This is unlikely to get improved, to be honest. I don't get why people insist on adding 4 extra characters ("www.") to their URL shortener...)


Note: comments here are not monitored. Don't expect support from the project here.

Comment by ofu...@gmail.com, Nov 23, 2010

Note that this doesn't work if your admin folder is using htpasswd protection to authenticate users.

Comment by interfa...@gmail.com, Jan 11, 2011

I would suggest adding this to the .htaccess to make sure people can reach the admin folder even when htpasswd protection is in place.

RewriteCond %{REQUEST_URI} (/|\.php|/[^.]*)$  [NC]
Comment by interfa...@gmail.com, Jan 11, 2011

And if you use the QR code plugin, you should use this rule instead:

RewriteCond %{REQUEST_URI} (/|\.php|\.qr|/[^.]*)$  [NC]
Comment by klammer...@gmail.com, Feb 3, 2011

If you see all of the files of Yourls listed when you call your short-url without any short url

'http://myshortdomain.url' instead of 'http://myshortdomain.url/link'

then just put some simple index.html in same directory where you have installed Yourls.

Comment by willbea...@gmail.com, Jun 2, 2011

Hey has anyone translated these rules to work with nginx?

Comment by ian...@gmail.com, Aug 6, 2011

here is the .htaccess code if you want to force www if that is how your install domain is in config.php

RewriteEngine? On RewriteCond? %{HTTP_HOST} !^www\. RewriteRule? ^(.)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Comment by nick...@gmail.com, Aug 14, 2011

I'd like to second the request for the correct nginx rewrite configuration. I've used this one here http://foolrulez.org/blog/2009/08/foolz-us-make-yourls-work-on-nginx/ but it doesn't support the + for stats.

Comment by nick...@gmail.com, Aug 14, 2011

Ok, I've found the solution to the nginx rewrite problem - it was in the comments on the Foolrulez website:

location / {
index index.php index.html index.htm; if (!-e $request_filename) {
rewrite ^ /yourls-loader.php last;
}
}
Comment by malco...@gmail.com, Nov 16, 2011

Is it possible to redirect the root domain without affecting the rest of the shortened URLs?

Comment by davidpun...@gmail.com, Dec 4, 2011

you sould add this to your .htaccess

RewriteEngine? on RewriteCond? %{HTTP_HOST} yourshorturl\.com NC? RewriteCond? %{REQUEST_URI} ^/$ Rewriterule ^(.)$ http://redirectedhere.com/ [L,R=301]

This should do the trick.

Comment by project member ozh...@gmail.com, Dec 4, 2011

Duh... you simply put <?php header('Location: http://blah/'); ?> in an index.php .....

Comment by t...@aperim.com, Jan 3, 2012

Erm.. it's not really a "Duh" moment.. putting the header / location in the index file generates a cyclic redirect. However - I also can't use the comment above

Comment by project member ozh...@gmail.com, Jan 4, 2012

No it does not generate a cyclic redirect... Unless you redirect it to itself, obviously.

Comment by shiblikh...@gmail.com, Jan 4, 2012

Got Something

HEHEHE

Comment by shiblikh...@gmail.com, Jan 4, 2012

ohhk, it's of google, now i'll believe it 100% ...

Comment by ela...@gmail.com, Apr 6, 2012

If you are installing it in a subdirectory, how would you modify > Bonus: Force non-WWW

Comment by m...@1to.co, Apr 12, 2012

i really think to make your install as safe as possible you should ad:

# Prevent .htaccess and .htpasswd files from being viewed by web clients <Files "^\.ht">

Order allow,deny Deny from all
</Files>

# Protect files <Files ~ "^(.)\.(inc|inc\.php|tpl|sql)$">

Order deny,allow Deny from all
</Files>

# Disable directory browsing Options -Indexes

Comment by rainer.r...@gmail.com, Apr 21, 2012

...still get the message: You don't have permission to access /admin/install.php on this server and I followed the guideline for version 1.4.3 precisely. Can't access this tool :-(


Sign in to add a comment
Powered by Google Project Hosting