mod_rewrite problem on shared host

Using a single web hosting account to host multiple sites

mod_rewrite problem on shared host

Postby GrimGreap » Mon Jun 30, 2008 12:51 pm

Hi,

I have a problem on my shared host with mod_rewrite. Tried using two CMSs with the mod_rewrite features (Joomla and Drupal) and the only way I can get them to work is to add my host username to the address, e.g

http://www.example.com/admin doesnt work, but
http://www.example.com/~username/admin does.

This is using htaccess with:
Code: Select all
RewriteBase /

If I use:
Code: Select all
#RewriteBase /
then nothing works.

If I use:
Code: Select all
RewriteBase /~username
then navigating to the site with the ~username all the links change to add it in, but no effect to leaving the URL without the username.

Contacted my host but they have no ideas. Any suggestions?
GrimGreap
 
Posts: 5
Joined: Mon Jun 30, 2008 12:30 pm

Postby richardk » Mon Jun 30, 2008 1:12 pm

What is the mod_rewrite?

Try
Code: Select all
RewriteBase /~username/
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby GrimGreap » Mon Jun 30, 2008 1:22 pm

The full rewrite is (for Drupal):

Code: Select all
RewriteEngine on

RewriteBase /

# Rewrite URLs of the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]


Tried it with /~username/ and it is the same as having /~username
GrimGreap
 
Posts: 5
Joined: Mon Jun 30, 2008 12:30 pm

Postby richardk » Tue Jul 01, 2008 3:45 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine on

# Rewrite URLs of the form 'index.php?q=x'.
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /~username/index.php?q=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby GrimGreap » Wed Jul 02, 2008 10:53 am

This gives me a 404 error even when trying with multiple RewriteBase combinations. But still works when accessing from http://www.example.com/~username/
GrimGreap
 
Posts: 5
Joined: Mon Jun 30, 2008 12:30 pm

Postby richardk » Fri Jul 04, 2008 1:59 pm

Does it redirect it if your replace QSA with R? You could try P instead of QSA, too.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby GrimGreap » Fri Jul 04, 2008 2:51 pm

Hi, The following are with calls to http://www.example.com/admin and what the URL changes to

With:
Code: Select all
RewriteRule ^(.*)$ /~username/index.php?q=$1 [R,L]

http://www.example.com/~username/index. ... html/admin (Page not found)

With:
Code: Select all
RewriteRule ^(.*)$ index.php?q=$1 [R,L]

http://www.example.com/index.php?q=/hom ... html/admin (Page not found)

With:
Code: Select all
RewriteRule ^(.*)$ index.php?q=$1 [P,L]

http://www.example.com/admin (Page not found)

With:
Code: Select all
RewriteRule ^(.*)$ /~username/index.php?q=$1 [P,L]

http://www.example.com/admin (Page not found)
GrimGreap
 
Posts: 5
Joined: Mon Jun 30, 2008 12:30 pm

Postby richardk » Fri Jul 04, 2008 3:00 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine on

# Rewrite URLs of the form 'index.php?q=x'.
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^/home//username/public_html/(.*)$ /~username/index.php?q=$1 [QSA,L]


Also try replacing
Code: Select all
/~username/index.php?q=$1

with
Code: Select all
/home/username/public_html/index.php?q=$1
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby GrimGreap » Fri Jul 04, 2008 3:22 pm

Whoooooo :D
Code: Select all
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^/home//username/public_html/(.*)$ /~username/index.php?q=$1 [QSA,L]

Worked, but it also changed all links on pages to include username so I changed it to:
Code: Select all
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^/home//username/public_html/(.*)$ /index.php?q=$1 [QSA,L]


Thanks for your help! Any ideas on what would cause it to be like this?
GrimGreap
 
Posts: 5
Joined: Mon Jun 30, 2008 12:30 pm

Postby richardk » Mon Jul 07, 2008 1:28 pm

I don't know exactly why it happens, but it's to do with the document root or prefix variable that mod_rewrite when it tries to remove the "per-directory prefix". It's probably due to how your host handles the domains and sub domains.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 34 guests

cron