Solved

htaccess file does not work

Posted on 2015-02-09
22
161 Views
Last Modified: 2015-02-10
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
Comment
Question by:canu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 10
22 Comments
 
LVL 18

Expert Comment

by:Lucas Bishop
ID: 40599217
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
 

Author Comment

by:canu
ID: 40599265
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
 
LVL 18

Expert Comment

by:Lucas Bishop
ID: 40599327
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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:canu
ID: 40599728
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
 
LVL 18

Expert Comment

by:Lucas Bishop
ID: 40599739
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
 

Author Comment

by:canu
ID: 40599744
OK, great, thanks a million for the explanation, let me put this together and I will let you know how I make out.
0
 
LVL 18

Accepted Solution

by:
Lucas Bishop earned 500 total points
ID: 40599760
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
 

Author Comment

by:canu
ID: 40599792
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
 
LVL 18

Expert Comment

by:Lucas Bishop
ID: 40599796
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
 
LVL 18

Expert Comment

by:Lucas Bishop
ID: 40599822
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
 

Author Comment

by:canu
ID: 40599826
Got it, thanks Lucas.
0
 

Author Comment

by:canu
ID: 40599855
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
 
LVL 18

Expert Comment

by:Lucas Bishop
ID: 40599865
I notice $ missing after php in what you pasted. Try with php$
0
 

Author Comment

by:canu
ID: 40599896
OK I tried that, I have a redirect loop again I'm afraid
0
 

Author Comment

by:canu
ID: 40599914
Hi again,

Could this be the problem?:

redirect 301 / /v2/
0
 

Author Comment

by:canu
ID: 40600942
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
 
LVL 18

Expert Comment

by:Lucas Bishop
ID: 40601040
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
 

Author Comment

by:canu
ID: 40601137
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
 
LVL 18

Assisted Solution

by:Lucas Bishop
Lucas Bishop earned 500 total points
ID: 40601175
Interesting. Try a redirectmatch instead:

RedirectMatch 301 ^/$ /v2

Open in new window

0
 

Author Comment

by:canu
ID: 40601259
That worked well!

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

Author Comment

by:canu
ID: 40601307
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
 
LVL 18

Expert Comment

by:Lucas Bishop
ID: 40601478
Happy to help!
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question