Solved

.htacess redirect not working

Posted on 2011-09-16
5
257 Views
Last Modified: 2012-05-12
Hi,

I've just changed the name of one of my php pages and I'm wanting to redirect requests made to the former filename to go to the new filename.

The old page is:
news/event.php?event=

The new page is:
news/predictions.php?event=

I tried using this in .htaccess:

RewriteRule ^news/predictions.php?event=([0-9]{2}) news/predictions.php?event=$1 [r=301,nc]

I tried accessing the orginal url but it didnt redirect me to the new one. Can anyone see where i'm going wrong?

Thanks,

Paul

Am I using this wrong? I tried
0
Comment
Question by:m0tSiE
[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
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:Derokorian
ID: 36550176
First you are redirecting from prediction to predictions. This is a problem. Secondly, you never close your pattern using the $ symbol. Finaly, I think you can use:

RewriteRule ^news/event.php$ news/predictions.php [QSA,R=301,NC]

HTH
0
 

Author Comment

by:m0tSiE
ID: 36550223
Thanks Derokorian, I tried your code and it does redirect but it uses the full server path including public_html, etc. is there a way to stop it adding in those extra folders? or should I just change news/predictions.php to the full url?
0
 
LVL 11

Assisted Solution

by:Amar Bardoliwala
Amar Bardoliwala earned 50 total points
ID: 36550266
Hello m0tSiE,

You can try any of following

1. add full url like http://yoursite.com/news/predictions.php

or

2. try /news/predictions.php

Hope this helps.

Thank You.

0
 
LVL 10

Accepted Solution

by:
Derokorian earned 450 total points
ID: 36550317
Personally I use:


RewriteEngine ON
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule (.+) $1 [L]

#other rewriterules here such as yours:
RewriteRule ^news/event.php$ news/predictions.php [QSA,R=301,NC]

Open in new window



or you can use the leading slash as amar suggested
0
 

Author Closing Comment

by:m0tSiE
ID: 36550331
Thanks guys, worked perfectly.

:)
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

707 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