gerbz / Yourls-Swap-Short-Url

Swap out the shorturls created by yourls if you want to point them somewhere else.
11 stars 5 forks source link

How to use with WP site .htaccess #9

Open davids701124 opened 9 years ago

davids701124 commented 9 years ago

Hi thanks for making this useful plugin.

I tried to use this with my WP site. My WP site install in the root and Yourls installed in the subfolder. When I use this together. For example, if I make google.com to mysite.com/g. The shorten url will be point to WP's 404 page. I think it's because this line

RewriteRule . /index.php [L]

I tried to comment it out, the shorten url will work. However, all links on my site won't work anymore. For example

mysite.com/about
mysite.com/works/01

I'm not an expert for .htaccess configuration. Could you guide me is there a way to make this work. How should I rewrite the rule? Thank you.

The original .htaccess is following

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

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

RewriteRule ^([0-9A-Za-z]+)/?$ http://mysite.com/yourl/yourls-go.php?id=$1 [L]
RewriteRule ^([0-9A-Za-z]+)\+/?$ http://mysite.com/yourl/yourls-infos.php?id=$1 [L]
RewriteRule ^([0-9A-Za-z]+)\+all/?$ http://mysite.com/yourl/yourls-infos.php?id=$1&all=1 [L]

# END YOURLS
BorysekOndrej commented 9 years ago

Hi there. Quite some time ago, I have encountered a similar issue. I am hosting YOURLS on subdomain, but with little changes it should also work for folder on main domain. This is the relevant part of my .htaccess to your question.

``` RewriteEngine On ## BEGIN YOURLS RewriteBase / RewriteCond %{HTTP_HOST} !^links.mysite.net RewriteRule ^([0-9A-Za-z]+)\+/?$ http://links.mysite.net/$1+ [L] RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([0-9A-Za-z]+)/?$ http://links.mysite.net/yourls-go.php?id=$1 [L] RewriteRule ^([0-9A-Za-z]+)\+/?$ http://links.mysite.net/yourls-infos.php?id=$1 [L] RewriteRule ^([0-9A-Za-z]+)\+all/?$ http://links.mysite.net/yourls-infos.php?id=$1&all=1 [L] # END YOURLS # BEGIN WordPress RewriteBase / RewriteRule ^index\.php$ - [L] # add a trailing slash to /wp-admin RewriteRule ^wp-admin$ wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteCond %{HTTP_HOST} !^domains.mysite.net [NC] RewriteRule ^ - [L] RewriteRule ^(wp-(content|admin|includes).*) $1 [L] RewriteRule ^(.*\.php)$ $1 [L] RewriteRule . index.php [L] # END WordPress ```