Link to home
Start Free TrialLog in
Avatar of canu
canuFlag for Antigua and Barbuda

asked on

htaccess file does not work

Hi,
I've created an .htaccess file to redirect an existing php website to the new Wordpress site and the redirect doesn't seem to be working.

Here's a sample of the code:

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>

order deny,allow

deny from all

allow from all

</Limit>

<Limit PUT DELETE>

order deny,allow

deny from all

</Limit>

AuthName www.website.com

redirect 301 index.html   http://website.com/v2/
redirect 301 index.php      http://website.com/v2/
redirect 301 index.php?p=home      http://website.com/v2/
redirect 301 index.php?p=oldpage http://website.com/v2/newpage/


I checked the syntax using an online checker and everything seems to be in order.

Does anyone have any idea why it's not working?

Any help or pointers would be much appreciated.



Thanks!
Avatar of Lucas Bishop
Lucas Bishop
Flag of United States of America image

These redirects are to a new location within the same web-site, not to a new web-site, correct? If so, you can do away with the FQDN. Try this:

redirect 301 /index.html /v2/
redirect 301 /index.php /v2/
redirect 301 /index.php?p=home /v2/
redirect 301 /index.php?p=oldpage /v2/newpage/

Open in new window


Also, added the root path to the beginning of each index file. This way just the index files in the root will be part of the redirect.

Also, there were unnecessary spaces before the /v2/ which may have been problematic.

Try this and report back.
Avatar of canu

ASKER

Thanks for the quick response and you are right, the redirects are to new locations in the same website.

I changed the redirect as you suggested but unfortunately received a internal configuration error as a result.

I must have missed something obvious, would it be the root path as you mentioned and if so, what steps do I need to take?

Apologies for the 'simple' questions but I'm not technical in the least (yet) so if you could take another look at this, that would be great.
Just noticed RewriteEngine isn't specified as 'on' in your code. Added that and changed the redirect for the query strings to be rewrites. Give this a shot:

RewriteEngine on

redirect 301 / /v2/

RewriteCond %{QUERY_STRING} ^id=home$
RewriteRule ^index.php /v2/ [NC,R=301]

RewriteCond %{QUERY_STRING} ^id=oldpage$
RewriteRule ^index\.php$ /v2/newpage [NC,R=301,L]

Open in new window

Avatar of canu

ASKER

Thanks for the suggestion. I took a look at this and from what I understand, if I used this method, what would be displayed after the rewrite is the old URL rather than the new URL, is that correct?

If so, is it would be possible to use a redirect rather than a rewrite?


Thanks again...
RewriteCond %{QUERY_STRING} ^id=home$

Open in new window


Look for query string containing "id=home".

RewriteRule ^index.php /v2/ [NC,R=301]

Open in new window


If condition is met ('id=home' string is found (Not Case sensitive)), Rewrite index.php to /v2/ via 301 Redirect
Avatar of canu

ASKER

OK, great, thanks a million for the explanation, let me put this together and I will let you know how I make out.
ASKER CERTIFIED SOLUTION
Avatar of Lucas Bishop
Lucas Bishop
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of canu

ASKER

Thanks, just one more thing.

Which ReWrite Rule line is correct:

RewriteRule ^index.php /v2/ [NC,R=301]

or

RewriteRule ^index\.php$ /v2/newpage [NC,R=301,L]

Thanks again!
L means it's the last line to process and to keep any sort of loop from occurring, so that should only be on the last line.

For escaping the . before php, the back slash should be used on both links.

RewriteEngine on

redirect 301 / /v2/

RewriteCond %{QUERY_STRING} ^p=home$
RewriteRule ^index\.php$ /v2/ [NC,R=301]

RewriteCond %{QUERY_STRING} ^p=oldpage$
RewriteRule ^index\.php$ /v2/newpage [NC,R=301,L]

Open in new window

Also, being that you have to do this on a variety of links, I'd recommend simply testing one link out first. For example, just test out:

RewriteCond %{QUERY_STRING} ^p=home$
RewriteRule ^index\.php$ /v2/ [NC,R=301]

Open in new window


If that works as expected, then move on to testing the next one and so forth.
Avatar of canu

ASKER

Got it, thanks Lucas.
Avatar of canu

ASKER

OK, I tried using the following code:

RewriteEngine on

redirect 301 / /v2/

RewriteCond %{QUERY_STRING} ^p=home$
RewriteRule ^index\.php /v2/ [NC,R=301,L]

Unfortunately, with or without the L, I received a Redirect Loop I'm afraid so I replaced it with the original htaccess file.
I notice $ missing after php in what you pasted. Try with php$
Avatar of canu

ASKER

OK I tried that, I have a redirect loop again I'm afraid
Avatar of canu

ASKER

Hi again,

Could this be the problem?:

redirect 301 / /v2/
Avatar of canu

ASKER

I did a bit of research and found that this line did cause problems.

I have since tested the .htaccess file and it seem to redirect where there is a page in particular specified for example:

RewriteCond %{QUERY_STRING} ^p=included$
RewriteRule ^index\.php$ /v2/comeswith/ [NC,R=301]

where included was the old page and /v2/comeswith/ is the new page.

What I'm trying to find is a command that will direct visitors to the home page to the new home page, that is

http://website.com/ to http://website.com/v2/ where v2 is the new home directory.

I've tried a few different variations without any success e.g.

RewriteRule   ^/$  /v2/  [R]

RewriteRule   ^\$  /v2/  [R]

and

RedirectMatch ^/$ http://website.com/v2/

I'm sure that this is a simple thing to solve but if anyone has any ideas, that would be great.


Thanks!
This code should direct anyone who visits the original homepage (root directory) to the new homepage (/v2).
redirect 301 / /v2/

Open in new window


What happens when you use only this redirect in your htaccess?

It's basically a simplified way of saying:
redirect 301 /index.html /v2/
redirect 301 /index.php /v2/

Open in new window


This is just for the homepage redirect though. To get those old pages that are defined with query strings to redirect to new versions, we'll need to figure out the right version of the code you posted above.
Avatar of canu

ASKER

Unfortunately, I receive a redirect loop.

I was able to get a page to redirect without any problem, it's just the home page that I'm having difficulties with.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of canu

ASKER

That worked well!

I'm just going to upload the rest of the pages, wish me luck.
Avatar of canu

ASKER

All seems to be well, no more redirect errors and pages are forwarding as they should.

Thank you so much for your help and patience, it's been invaluable.
Happy to help!