cancel
Showing results for 
Search instead for 
Did you mean: 

help with htaccess redirect

brin57
Dabbler
Posts: 18
Registered: ‎19-12-2008

help with htaccess redirect

Can someone help please.
I have a domain that points to my ccgi.username.plus.com webspace. I have loaded Wordpress in a subdirectory of public. ccgi.../public/wordpress.
I want to point my domain name to the Wordpress directory where I have created a site (which works perfectly when I open that subdirectory) and have been told to do this by changing the .htaccess file. But which one and what command ?
I have an .htaccess  in my "/" directory and one in my "/Wordpress" directory (I assume its not this one as its not being accessed when entering my domain name).
The contents of the / .htaccess file is
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^cgi-bin(/.*|)$ CGI-BIN$1 [L,NC]
Options +ExecCGI
AddHandler cgi-script .cgi .pl
What command do I enter and where in the .htaccess file do I put it ?
For completeness the contents of the Wordpress .htaccess is
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ -
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php
</IfModule>
# END WordPress
I've looked at www.htaccessredirect.co.uk but still find it confusing.
I also have index.php files in /public and /public/wordpress
Thanks for any help
21 REPLIES 21
spraxyt
Superuser
Superuser
Posts: 10,063
Thanks: 1,369
Fixes: 75
Registered: ‎06-04-2007

Re: help with htaccess redirect

To do this you need to create a .htaccess in /public ( i.e. /public/.htaccess ) with contents as follows. For illustration purposes I have assumed your domain is ccgi.domain.co.uk - obviously this needs to be replaced by the correct one. Putting \ in front of dots is necessary to make them into real dots rather than regex meta characters matching any character.

RewriteEngine On
# Point domain to /wordpress folder
RewriteCond %{HTTP_HOST} ^ccgi\.domain\.co\.uk$ [NC]
RewriteCond %{REQUEST_URI} !^/wordpress/
RewriteRule (.*) /wordpress/$1

I assume you want to hide /wordpress from visitors. To avoid this appearing in WordPress links you need to log into your WordPress dashboard, go to Settings (General) and remove /wordpress from the WordPress Address (URL) and Site Address (URL) entries.
David
Edit: You also need to remove /wordpress from two directives in the .htaccess in /public/wordpress so this will become

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ -
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
</IfModule>
# END WordPress

Edit2: WordPress creates the /public/wordpress/.htaccess file itself during set-up. So it's possible it might update it itself when the dashboard URL changes are saved. Checking the file date (via FTP) should give a clue if this happens.
David
brin57
Dabbler
Posts: 18
Registered: ‎19-12-2008

Re: help with htaccess redirect

Many thanks David.
I will try it tonight when I get home.
Brian
brin57
Dabbler
Posts: 18
Registered: ‎19-12-2008

Re: help with htaccess redirect

David
HELP !
I changed the .htaccess as suggested by you. It didn't seem to work.
I then changed the .htaccess in the wordpress folder as suggested. It didn't seem to do anything.
I then went into my wordpress site and deleted the "/wordpress" x 2 in the Settings folder as suggested by you
I've now lost the theme (although the content seems to be there) and I can't access the wp-admin area.
I've changed both .htaccess files back to their original.
Stupidly I didn't back up the latest wordpress site before doing this !
Tell me I can get back to where I was please - and how.
Many thanks
Brian
spraxyt
Superuser
Superuser
Posts: 10,063
Thanks: 1,369
Fixes: 75
Registered: ‎06-04-2007

Re: help with htaccess redirect

Oh dear. Sad
Did you originally have a /public/.htaccess file? Perhaps containing:

Options +ExecCGI
AddHandler cgi-script .cgi .pl

The way I read your description I thought those were in /.htaccess .
To try to recover access to the control panel I suggest disabling /public/.htaccess ( eg rename the file to original.htacess ) and do the same rename to /public/wordpress/.htaccess.
If you browse to ccgi.domain.co.uk/wordpress do you get the dashboard, perhaps with a broken theme?
David
Edit: you could also try to access it using your username rather than domain ( ccgi.username.plus.com/wordpress )
David
spraxyt
Superuser
Superuser
Posts: 10,063
Thanks: 1,369
Fixes: 75
Registered: ‎06-04-2007

Re: help with htaccess redirect

Brian
You can reset the URL settings you changed by going into and editing the MySQL tables. Do you have phpMyAdmin set up? If not (maybe in any case) I suggest you download Adminer - choose the Adminer 4.2.1 for MySQL ... English only (.php, 189 kB) version. It's just a single file called adminer-4.2.1-mysql-en.php .
To make usage easier I suggest creating a folder with a suitable name (eg adminer), move that file into it and rename it to index.php . Then upload the folder (and file) to /public using FileZilla. If you browse to ccgi.username.plus.com/adminer the Adminer login screen should open. To login you need the Servername ( which is sql5c51a.megasqlservers.eu ), and the database Username and Password. You can leave the Database field empty.
After login you should see two database entries, information_schema and your database. Click the latter name to display its tables.
Assuming you left the WordPress table prefix as wp_ click wp_options in the column on the left to select it. Click Select data to show table contents.
You need to Edit two rows, option_id 1 (siteurl) and 37 (home) to correct the URLs. (Individually) click Edit in the Modify column, add /wordpress to the option_value entry and save the change.
Click Logout top right to logout.
After making those changes I hope you will be able to get to the site home page. Links will probably not work since /public/wordpress/.htaccess has been disabled. Assuming the home page is OK you could try enabling the latter .htaccess again to see if it works.
Hope this at least restores operation. Cool
David
David
brin57
Dabbler
Posts: 18
Registered: ‎19-12-2008

Re: help with htaccess redirect

David
Thank you again for being patient with me and your help.
As it so happens in the mean time I've managed to restore my website by following the instructions in Changing the Site URL in the Wordpress Codex. So I have got my site operating correctly.
I have also added the .htaccess file in /public and amended the .htaccess in the wordpress folder. So now, when I type in ccgi.xxxx.plus.com it automatically redirects me to the Wordpress website - thank you. However I have a domain that is supposedly pointing to that same URL but everytime I enter the domain name it just comes up with the  No Pages Loaded page. So I still can't get directly to my website with my required domain ! Frustrating.
I have an open question with plusnet on this but I have to say, unfortunately I have not been overly impressed with them to date.
I have not tried deleting the /wordpress from the Setttings area again as I am frightened that my site will crash again - am I doing anything wrong ?  At least I've backed up the site this time just in case !
Many thanks again
Brian
spraxyt
Superuser
Superuser
Posts: 10,063
Thanks: 1,369
Fixes: 75
Registered: ‎06-04-2007

Re: help with htaccess redirect

I assume the following line from my reply above
RewriteCond %{HTTP_HOST} ^ccgi\.domain\.co\.uk$ [NC]
in /public/.htaccess now looks like
RewriteCond %{HTTP_HOST} ^ccgi\.xxxx\.plus\.com$ [NC]
If you want just your domain to redirect into /wordpress you need to replace ccgi\.xxxx\.plus\.com with your domain-based hostname. That will mean your username-based hostname will provide access to anywhere in your ccgi filespace. If you want all references redirected you can comment out that line by adding # in column 1 (or remove the line completely).
If there are other domains *not* to be redirected you need an OR condition like
RewriteCond %{HTTP_HOST} ^ccgi\.xxxx\.plus\.com$ [OR,NC]
RewriteCond %{HTTP_HOST} ^your\.domain\.hostname\.here$ [NC]
For testing purposes navigation will work fine with /wordpress in URL settings. All that will happen is that on clicking a link /wordpress will appear in the browser address field. Once you are happy deleting /wordpress in settings will remove it from links.
David
David
brin57
Dabbler
Posts: 18
Registered: ‎19-12-2008

Re: help with htaccess redirect

David
You must think me thick.
You were right, the line mentioned looked like
RewriteCond %{HTTP_HOST} ^ccgi\.xxxx\.plus\.com$ [NC]
So I changed it to
RewriteCond %{HTTP_HOST} ^www\.domain\.co\.uk$ [NC] as you suggested
So, now when I access ccgi..... it comes up with No Pages Loaded and doesn't redirect me to /Wordpress
However, that's the same with wwww.domain.co.uk -  it comes up with No Pages Loaded and doesn't redirect me to /Wordpress
I can access the Wordpress area by going to either www.domain.co.uk/wordpress or ccgi.../wordpress but I just can't seem to get them redirecting automatically.
I also tried # out the RewriteConf %HTTP_HOST] line and that didn't help.
I must be doing something wrong.
Sorry to ask again.
Thanks
Brian

spraxyt
Superuser
Superuser
Posts: 10,063
Thanks: 1,369
Fixes: 75
Registered: ‎06-04-2007

Re: help with htaccess redirect

Brian
Finding out the redirect worked with ccgi.username... was useful as it shows the set-up is capable of working (as it should be). The domain version not working makes me think its .htaccess is not understood by Apache. My guess is that it was not uploaded as ASCII so that its line endings are CRLF rather than just LF. Dealing with 'dot' files on Windows can be tricky, and CRLF line endings on Linux are best avoided.
The way I handle .htaccess on my PC is to work with (edit in a text editor, eg notepad) an htaccess.txt file (which Windows is happy with). FileZilla will upload that as ASCII and you should notice the file size on the server is smaller by the number of lines (-1 if 'newline' was omitted on the last line). Then use FileZilla to rename the file ( remove .txt and add a leading . ).
I'm assuming FileZilla is set to do "AUTO" transfers by default.
Hope that makes sense.
David
David
brin57
Dabbler
Posts: 18
Registered: ‎19-12-2008

Re: help with htaccess redirect

David
I could kiss you !! Grin
All works fine as far as I can tell.
Thank you so much for your help it is really appreciated.
Still slightly nervous about deleting the /wordpress in the Settings but I may be brave enough to give it a try later.
Thank you again.
Brian
brin57
Dabbler
Posts: 18
Registered: ‎19-12-2008

Re: help with htaccess redirect

David
Sorry, spoke too soon !
It all works well when typing in www.domain.co.uk but it doesn't work with just domain.co.uk. Is there any other command I need to include in the .htaccess.
I have a couple of other domains, domain.com for example that I would also like to redirect to this webspace - do I need to add them to the .htaccess as well ?
Thanks (yet again)
Brian

spraxyt
Superuser
Superuser
Posts: 10,063
Thanks: 1,369
Fixes: 75
Registered: ‎06-04-2007

Re: help with htaccess redirect

Brian
If you replace
RewriteCond %{HTTP_HOST} ^www\.domain\.co\.uk$ [NC]
with
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.co\.uk$ [NC]
it will make the presence of www. optional.
However at the risk of entering a minefield that means you will have two different sites (www and non-www) with identical contents. From a visitor point of view, apart from slight confusion, it doesn't matter. However Google might downgrade your site ranking due to duplicate pages. Does this bother you? This problem can be fixed by doing a permanent redirect to the preferred style.
For dealing with 'other domains' you need to clarify what you want to do. To me "webpace" means the whole of this ccgi site. Is that what you meant or did you mean redirect them to domain-specific folders or all to the same /wordpress folder (or something else). Are the domains already hosted by Plusnet with DNS pointing to and hosted in your ccgi space on this server?
David
David
brin57
Dabbler
Posts: 18
Registered: ‎19-12-2008

Re: help with htaccess redirect

David
Thank you, that worked.
I would prefer not to be downgraded by Google if at all possible. You mentioned it may be possible to overcome this with a permanent redirect - can I be cheeky and ask how this is done ? I don't mind which version is the "default" if they both end up pointing to the .../wordpress directory.
Other domains. This is not so important. I have variations of domains based on my main domain to allow for wrong spellings and wrong extension i.e. .com rather than .co.uk. So I would like these to all point eventually to the same .../wordpress directory (so that means pointing to the /public area but then redirected by .htaccess to the /wordpress directory I assume) . These other domains are already pointing to my PlusNet .htdocs area where my old website is located. I appreciate I need to make some changes to the settings in my PlusNet domain area to get these to point at the ccgi area (with some assistance from PlusNet - I haven't done this yet as was waiting for this one to work properly first !) but am not sure what changes would be needed to the .htaccess file to allow for these extra domains.
Many thanks again.
Brian

spraxyt
Superuser
Superuser
Posts: 10,063
Thanks: 1,369
Fixes: 75
Registered: ‎06-04-2007

Re: help with htaccess redirect

Brian
To do permanent redirects from non-www URLs to their www equivalents (my preference) add the following three lines after RewriteEngine On and before the /wordpress rewrite block
# Rewrite non-www domain references to www equivalents
RewriteCond %{HTTP_HOST} ^domain\.co\.uk [NC]
RewriteRule ^(.*)$ http://www.domain.co.uk/$1 [R=301,L]
That will make www. appear in the browser address field if visitors use the non-www style.
For convenience I'll comment on 'other domains' in a separate reply. Smiley
David
David