ansQuestion
ansQuestion

Reputation: 1

Need help to recitfy htaccess RewriteRule & RewriteCond error

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

Upvotes: 0

Views: 41

Answers (0)

Related Questions