0
votes

I have Silverstripe installed on www.mywebsite.com (I made that up just as an example)

I am testing Wordpress on www.mywebsite.com/test

Here is my .htaccess file in my root folder:

### SILVERSTRIPE START ###

# Deny access to templates (but allow from localhost)
< Files *.ss >
Order deny,allow<br>
Deny from all<br>
Allow from 127.0.0.1
< /Files >

# Deny access to IIS configuration
< Files web.config >
Order deny,allow
Deny from all
< /Files >

# Deny access to YAML configuration files which might include sensitive information
< Files ~ "\.ya?ml$">
Order allow,deny
Deny from all
< /Files>

# Route errors to static pages automatically generated by SilverStripe
ErrorDocument 404 /assets/error-404.html
ErrorDocument 500 /assets/error-500.html

< IfModule mod_env.c>
# Ensure that X-Forwarded-Host is only allowed to determine the request
# hostname for servers ips defined by SS_TRUSTED_PROXY_IPS in your _ss_environment.php
# Note that in a future release this setting will be always on.
SetEnv BlockUntrustedIPs true
< /IfModule>

 < IfModule mod_rewrite.c>

 # Turn off index.php handling requests to the homepage fixes issue in apache >=2.4
  < IfModule mod_dir.c>
    DirectoryIndex disabled
  < /IfModule>

  SetEnv HTTP_MOD_REWRITE On
 RewriteEngine Off

  # Enable HTTP Basic authentication workaround for PHP running in CGI mode
 RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Deny access to potentially sensitive files and folders
RewriteRule ^vendor(/|$) - [F,L,NC]
RewriteRule silverstripe-cache(/|$) - [F,L,NC]
RewriteRule composer\.(json|lock) - [F,L,NC]

# Process through SilverStripe if no file with the requested name exists.
# Pass through the original path as a query parameter, and retain the existing parameters.
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* framework/main.php?url=%1 [QSA]

# If framework isn't in a subdirectory, rewrite to installer
RewriteCond %{REQUEST_URI} ^(.*)/framework/main.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . %1/install.php? [R,L]

< /IfModule><br>
### SILVERSTRIPE END ###

 < IfModule pagespeed_module>
ModPagespeed Off
</IfModule>
 < IfModule mod_expires.c><br>
  ExpiresActive Off<br>
< /IfModule>

Code on /test/.htaccess:

< IfModule mod_rewrite.c><br>
SetEnv HTTP_MOD_REWRITE On<br>
RewriteEngine On<br>
RewriteBase /<br>
RewriteCond %{REQUEST_URI} !/test<br>
RewriteEngine On<br>
RewriteCond %{REQUEST_FILENAME} !-f<br>
RewriteCond %{REQUEST_FILENAME} !-d<br>
RewriteRule . /index.php [L]<br>
< /IfModule> 

Any ideas? Note: The < br > does not show up in the actual file and there are no spaces between the < and >

I get a list of all my files. My index.php file doesn't even show up properly and the URL changes from /test to test/?url=/test

I use zoom.ph shared hosting.

Update:

My new code in the root .htacccess file:

RewriteEngine On

# Change any direct URLs (www.unclebubby.com...) to the subdomain   (wavs.unclebubby.com)
RewriteCond %{HTTP_HOST} ^(www\.)?collegeconnect\.ph$ [NC] 
RewriteCond %{REQUEST_URI} ^/test/(.*)$ [NC] 
RewriteRule .* http://test.collegeconnect.ph/%1 [R=301,L]
RewriteCond %{REQUEST_URI} !/test

 # If there is a .htm at the end of the URL, get rid of it (due to migration of site from FrontPage)
RewriteCond %{REQUEST_URI} ^/(.+)\.htm$ [NC] 
RewriteRule ^.+\.htm$ /%1 [R=301,L]

RewriteBase /

### SILVERSTRIPE START ###
3
You're installing wordpress in a subfolder of SilverStripe? - scrowler
Yes I am, which Silverstripe doesn't really make easy to do. - Thomas
If you're using a subDOMAIN like test.mysite.com you should make a different virtual host in your webserver config. Installing it in a subFOLDER (mysite.com/test) is a bit tricker. I'd go for a seperate virtualhost to have clean installations. - wmk

3 Answers

1
votes

I tested this and what you have seems to work fine. Just ensure you have no errors in your htaccess. You can check apache.log for this.

Here's what I used:

DirectoryIndex index.html index.php
<IfModule mod_rewrite.c>
SetEnv HTTP_MOD_REWRITE On
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/test
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

This redirected me successfully to the Wordpress setup page (fresh install).

0
votes

First, your RewriteBase in test/.htaccess is wrong. It's not "/" (root), but "/test/" (as files are there).

Second, you have "RewriteEngine On" twice in your test/.htaccess - which may not be an error, but not needed anyway.

Third - your test/.htaccess file is literally disabled by itself by line:

RewriteCond %{REQUEST_URI} !/test

which means - all requests that don't have "test" in URL, which no request to "test" folder can fullfil. Your test/.htaccess should look like this:

< IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /test/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
< /IfModule> 

BONUS: Silverstripe scans entire folder where it is installed and adds those classes to its manifest, which means you should exclude wordpress (ie folder "test") by placing empty file called "_manifest_exclude" in it.

0
votes

mention folder name in 'RewriteBase' like below in .htaccess file at your root path

RewriteBase '/SilverStripe/'

where SilverStripe be ur folder name like u mentioned

RewriteBase '/test/'

please do remember to add slash before and after the folder name. If it doesnt work , then let me know. Thanks