Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

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!
0
canu
Asked:
canu
  • 12
  • 10
2 Solutions
 
Lucas BishopCommented:
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.
0
 
canuWebmasterAuthor Commented:
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.
0
 
Lucas BishopCommented:
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

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
canuWebmasterAuthor Commented:
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...
0
 
Lucas BishopCommented:
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
0
 
canuWebmasterAuthor Commented:
OK, great, thanks a million for the explanation, let me put this together and I will let you know how I make out.
0
 
Lucas BishopCommented:
Slight change. Noticed I made a mistake and was using "id=" instead of "p=" like your strings are currently using.

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

0
 
canuWebmasterAuthor Commented:
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!
0
 
Lucas BishopCommented:
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

0
 
Lucas BishopCommented:
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.
0
 
canuWebmasterAuthor Commented:
Got it, thanks Lucas.
0
 
canuWebmasterAuthor Commented:
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.
0
 
Lucas BishopCommented:
I notice $ missing after php in what you pasted. Try with php$
0
 
canuWebmasterAuthor Commented:
OK I tried that, I have a redirect loop again I'm afraid
0
 
canuWebmasterAuthor Commented:
Hi again,

Could this be the problem?:

redirect 301 / /v2/
0
 
canuWebmasterAuthor Commented:
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!
0
 
Lucas BishopCommented:
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.
0
 
canuWebmasterAuthor Commented:
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.
0
 
Lucas BishopCommented:
Interesting. Try a redirectmatch instead:

RedirectMatch 301 ^/$ /v2

Open in new window

0
 
canuWebmasterAuthor Commented:
That worked well!

I'm just going to upload the rest of the pages, wish me luck.
0
 
canuWebmasterAuthor Commented:
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.
0
 
Lucas BishopCommented:
Happy to help!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 12
  • 10
Tackle projects and never again get stuck behind a technical roadblock.
Join Now