Evanss
Evanss

Reputation: 23563

Htaccess file no longer working when moved from web root to folder

The following in my htacess file works to remove add a # character to the url. So mysite.com/page2 becomes mysite.com/#page2

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /#$1 [L,NE,R]

This works fine however my site is actually going to be in a folder in the web root, not the root itself. So I need something like existingsite.com/mysite/page2 to redirect to existingsite.com/mysite/#page2

Ideally I would like to have this controlled by the htaccess thats within my site folder so that I dont need to change the htaccess file for the main site. Ive moved the site (including the htaccess file) into a folder in the web root but now its not working like before (when it was in the web root).

Upvotes: 0

Views: 73

Answers (2)

Evanss
Evanss

Reputation: 23563

This works when placed in the htaccess file in the folder of the new site (not the web root).

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /santa7/#$1 [L,NE,R]

Upvotes: 0

Luceos
Luceos

Reputation: 6720

Use rewritebase:

RewriteBase /mysite/

And your existing rewrites:

RewriteEngine On
RewriteBase /mysite/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /#$1 [L,NE,R]

Also see: How does RewriteBase work in .htaccess

Upvotes: 1

Related Questions