0

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).

Evanss
  • 23,390
  • 94
  • 282
  • 505

2 Answers2

1

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

Community
  • 1
  • 1
Luceos
  • 6,629
  • 1
  • 35
  • 65
  • It doenst seem to work. Locally my path is http://localhost:8888/site7/one so ive used RewriteBase /site7/ – Evanss Dec 04 '13 at 12:47
  • Ive also tested at mytestingserver.com/site7 which also doesn't work. – Evanss Dec 04 '13 at 13:05
  • Can you confirm that the htaccess file should be in folder of the new site not the web root? – Evanss Dec 04 '13 at 13:15
  • It should be in the folder. I did not test this out, but documentation and examples both show this is thé solution. – Luceos Dec 05 '13 at 10:11
0

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]
Evanss
  • 23,390
  • 94
  • 282
  • 505
  • Just `RewriteRule ^([^/]+)/?$ #$1 [L,NE,R]` is better since that will not require change between your localhost and server. – anubhava Dec 04 '13 at 14:37