0

I have Wordpress multi-site installed and setup on domain.com and it is working. I have YOURLS admin access only installed and setup on sub.domain.com and it is working.

I know that they both can not be in the same server location as they do not work well together like that.

Wordpress is installed to public_html and YOURLS is installed to public_html/yourls.

My goal is to have a Wordpress multi-site site at sub.domain.com working along with yourls. This is where I start to come into problems with .htaccess. I do not know much about coding in .htaccess. This is what I have done and have found out.

So in cpanel I setup sub.domain.com to point to public_html/yourls and then installed yourls. Everything is working fine. Then through cpanel domains I changed the sub.domain.com to point to public_html instead of public_html/yourls. This does cause issues.

After backing up the public_html/ .htaccess file. I removed all code in the .htaccess file as I found out that if I added the following code

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} domain.com$
RewriteCond %{REQUEST_URI} !^/yourls/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /yourls/$1
RewriteCond %{HTTP_HOST} domain.com$
RewriteRule ^(/)?$ yourls/yourls-loader.php [L]
</IfModule>

Then the admin area for YOURLS works just fine. I am also able to create/delete and use YOURLS short yourls without a problem. So when I create a short url to https://randomdomain.com/random/domain/site/index.html it looks like https://sub.domain.com/shorturl and that is what I want and It does work correctly.

However now I need to get Wordpress back up and working. So I add all the Wordpress code back.

# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
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
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
</IfModule>

# END WordPress

Well after adding the Wordpress code back things don't play well together. So I did make some changes to the code and did some process of elimination as seen in the portion below.

RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{HTTP_HOST} sub.domain.com$
RewriteCond %{REQUEST_URI} !^/yourls/
#RewriteRule ^(.*)$ /yourls/$1
RewriteCond %{HTTP_HOST} sub.domain.com$
#RewriteRule ^(/)?$ yourls/yourls-loader.php [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]

The code that is #commented out will allow Wordpress to seem to work fine but not YOURLS. If I uncomment them out then YOURLS works fine but not the sub.domain.com Wordpress site. So this seems to be where the problems is. With me not understanding the .htaccess code much at all. I am not sure where what needs to be fixed or if even a [OR] statement can be used somewhere to get things working correctly with Wordpress & YOURLS.

Any help is much appreciated. Thanks

  • So, to be clear, you want `sub.domain.com/foo` to lead to a WordPress post, and `sub.domain.com/bar` should be a short URL? That can only work, if you have _some sort_ of pattern, that makes them distinguishable to the server on the .htaccess level. Like if your short URL service used some sort of token, f.e. a combination of digits and letters of a fixed length - then you could specifically match those requests, and let them "pass through" the WP rewriting. – CBroe Sep 29 '22 at 06:23
  • So my goal here is just to have a few set Wordpress pages for the sub.domain.com site. So there’s not a lot of pages and the few pages won’t change. Pages: Home, FAQ & Terms of Service. The yourls will be able to create any sub.domain.com/shorturl. So I think this would could work. Just how do I go about doing it? Thanks – ansQuestion Sep 29 '22 at 14:34
  • I should probably also note that the Wordpress multi-site has other sites as well. so I have sites that are domain.com, sub.domain.com, sub1.domain.com, sub2.domain.com, domain2.com, domain3.com and domain4.com. – ansQuestion Sep 29 '22 at 15:23
  • @CBroe, How would I go about doing this? – ansQuestion Sep 30 '22 at 15:22

0 Answers0