Solved

.htacess redirect not working

Posted on 2011-09-16
5
253 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
  • 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

776 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