Pergunta

I am trying to redirect www.example.org.uk to example.org.uk/subdirectory and then hide the subdirectory - so it only display www.example.org.uk on the address bar.

This is the original code (from https://my.bluehost.com/cgi/help/347) that I was using:

# BlueHost.com 
# .htaccess main domain to subdirectory redirect 
# Do not change this line. 
RewriteEngine on 
# Change example.com to be your main domain. 
RewriteCond %{HTTP_HOST} ^(www.)?example.org.uk$ 
# Change 'subdirectory' to be the directory you will use for your main domain. 
RewriteCond %{REQUEST_URI} !^/subdirectory/ 
# Don't change the following two lines. 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
# Change 'subdirectory' to be the directory you will use for your main domain. 
RewriteRule ^(.*)$ /subdirectory/$1 
# Change example.com to be your main domain again. 
# Change 'subdirectory' to be the directory you will use for your main domain 
# followed by / then the main file for your site, index.php, index.html, etc. 
RewriteCond %{HTTP_HOST} ^(www.)?example.org.uk$ 
RewriteRule ^(/)?$ subdirectory/index.php [L]

The problem is that none of this code works.

After searching Stackoverflow and using advice - this is the current code:

Options +FollowSymLinks -Multiviews

<IfModule mod_rewrite.c>

# BlueHost.com 
# .htaccess main domain to subdirectory redirect 
# Do not change this line. 
RewriteEngine on 
# Change example.com to be your main domain. 
RewriteCond %{HTTP_HOST} ^(www.)?grampianyoga.org.uk$ 
# Change 'subdirectory' to be the directory you will use for your main domain. 
RewriteCond %{REQUEST_URI} !^/gya2/ 
# Don't change the following two lines. 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
# Change 'subdirectory' to be the directory you will use for your main domain. 
RewriteRule ^(.*)$ /gya2/$1 
# Change example.com to be your main domain again. 
# Change 'subdirectory' to be the directory you will use for your main domain 
# followed by / then the main file for your site, index.php, index.html, etc. 
RewriteCond %{HTTP_HOST} ^(www.)?grampianyoga.org.uk$ 
RewriteRule ^(/)?$ gya2/index.php [L]</IfModule>

Unfortunately an internal error is displayed and this what the error file states:[Wed Mar 26 14:22:35 2014] [9566783] [core:alert] [client 97.74.104.6:60525] /var/chroot/home/content/83/9566783/html/.htaccess: RewriteRule: bad flag delimiters

I am using GoDaddy and I believe they have there own settings. Does anyone have any suggestions? Tried Support and apparently they are unable to help with scripting.

Foi útil?

Solução

I would change the line

RewriteCond %{REQUEST_URI} !^/subdirectory/

to

RewriteCond %{REQUEST_URI} !^/subdirectory/?

so that the trailing / is optional. The code, with the -f and -d checks, will not trigger if you happen to give an existing file or directory. Assuming not,

RewriteRule ^(.*)$ /subdirectory/$1 

should silently send visitors to the subdirectory (inserts /subdirectory before the existing URI).

I'm not sure why the last two lines are in there. They may be handled already if you take the trailing / requirement off (as mentioned above). Try commenting them out (with # ).

If it still doesn't work, there may be something different with GoDaddy's setup. You should discuss what you're trying to do with their tech support.

Update: modified version of your latest .htaccess

Options +FollowSymLinks -Multiviews

<IfModule mod_rewrite.c>

# BlueHost.com 
# .htaccess main domain to subdirectory redirect 
# Do not change this line. 
RewriteEngine on 
# Change example.com to be your main domain. 
RewriteCond %{HTTP_HOST} ^(www\.)?grampianyoga\.org\.uk$ 
# Change 'subdirectory' to be the directory you will use for your main domain. 
RewriteCond %{REQUEST_URI} !^/gya2
RewriteRule ^(.*)$ /gya2/$1 [L]

</IfModule>

The RewriteCond %{HTTP_HOST} ^(www\.)?grampianyoga\.org\.uk$ line is probably unnecessary (but harmless), unless you're working with parked domains, subdomains, add-on domains, etc.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top