cancel
Showing results for 
Search instead for 
Did you mean: 

htaccess redirect to subdir

pedroc
Dabbler
Posts: 18
Thanks: 1
Fixes: 1
Registered: ‎23-03-2008

Re: htaccess redirect to subdir

Thanks Spraxyt.  The following code will redirect  to the 'catalog' directory any request that specifically asks for index.php, , but fails if index.php is not mentioned because it then inserts www. before the link address, causing a 'not found' error.

/*Options +FollowSymLinks -MultiViews
#Turn mod_rewrite on
RewriteEngine On
RewriteBase /
Redirect /index.php http://test.solarproject.co.uk/catalog/
Options +ExecCGI
AddHandler cgi-script .cgi .pl

I am looking for the code to redirect all links to all files, not just the index file.
spraxyt
Resting Legend
Posts: 10,063
Thanks: 674
Fixes: 75
Registered: ‎06-04-2007

Re: htaccess redirect to subdir

That redirect is the mod_alias style which I think would loop for a same-server redirect from /.
Try the following .htaccess which uses mod_rewrite. The third RewriteCond prevents looping:

AddHandler cgi-script .cgi .pl
RewriteEngine On
RewriteCond %{HTTP_HOST} ^test\.solarproject\.co\.uk$ [NC]
RewriteCond %{REQUEST_URI} !^/cgi-bin/
RewriteCond %{REQUEST_URI} !^/catalog/
RewriteRule (.*) /catalog/$1

Do you have any content in /public/cgi-bin (which the second RewriteCond will avoid rewriting)?
David
David
pedroc
Dabbler
Posts: 18
Thanks: 1
Fixes: 1
Registered: ‎23-03-2008

Re: htaccess redirect to subdir

Thanks David, I hadn't expected a reply overnight!  - sadly your suggested htaccess code doesn't work for me.
Using that code, a request for      http://test/solarproject.co.uk/index.php ;     converts to      test.solarproject.co.uk/index.php      and throws up a '404not found' as the file is actually in the 'catalog' subdirectory.
A call for http://test.solarproject.co.uk/ converts to www.test.solarproject.co.uk/catalog and gives 'webpage not available'. If I remove the www then it finds the index file ok.
I have no content in cgi-bin, that line is left from the default .htaccess that was loaded in the server migration.
Does this give any clues?
bobpullen
Community Gaffer
Community Gaffer
Posts: 16,869
Thanks: 4,950
Fixes: 315
Registered: ‎04-04-2007

Re: htaccess redirect to subdir

I think you might be having problems because you're editing the .htaccess file in the root directory. Try commenting that out and creating an .htaccess in /public (or rename the one I've just put there that has a .bob file extension).

Bob Pullen
Plusnet Product Team
If I've been helpful then please give thanks ⤵

pedroc
Dabbler
Posts: 18
Thanks: 1
Fixes: 1
Registered: ‎23-03-2008

Re: htaccess redirect to subdir

Thanks Bob, using spraxyt's code in the /public directory has helped but not quite solved it.
If I call for     http://test.solarproject.co.uk/index.php      it works, inserting the required 'catalog' into the address.
But if I call    http://test.solarproject.co.uk       without specifying a file then it falls over because it then also inserts the prefix www  
  --i.e.    http://www.test.solarproject.co.uk/catalog/
If we can stop it assuming it is a www address then I think we've cracked it.
Any idea how to achieve that?
EDIT....Something seems to have changed overnight, everything seems to be working now. I am now looking at it on a different PC so I wonder if I was getting some interference from the browser cache when i was testing last night.
Thanks for the help, great forum.
spraxyt
Resting Legend
Posts: 10,063
Thanks: 674
Fixes: 75
Registered: ‎06-04-2007

Re: htaccess redirect to subdir

Glad to hear this works now. Smiley
Adding an unwanted www struck me as potentially browser related - trying to be helpful.
David
David