Solved

htaccess file does not work

Posted on 2015-02-09
22
153 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 17

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 17

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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 

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 17

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 17

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 17

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 17

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 17

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 17

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 17

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 17

Expert Comment

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

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What does GoogleTagMgr javascripts below do 5 87
Drop Down not working in mobile- Bootstrap 14 51
Replace value 2 55
Show MP4 file and close (HTA) 3 43
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

734 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