Solved

htaccess file does not work

Posted on 2015-02-09
22
145 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
  • 12
  • 10
22 Comments
 
LVL 16

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 16

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
 

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 16

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 16

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 16

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 16

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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 16

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 16

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 16

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 16

Expert Comment

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

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now