View Full Version : .htaccess riddle - guru needed!
davide101
08-07-2008, 02:38 PM
I have some working .htaccess code (below). I would love to make this a [R=301] permanent redirect so PageRank is passed from our old links. When I simply add [R=301] to the last statement, it adds .php to hte urls.
.htaccess below: /headlines/
.htacess with R=301: /headlines.php/
Any ideas on how to do this properly? I'm not sure why the redirect changes the working rewrite.
RewriteEngine On
RewriteBase /news/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/]+)/?(.*) $1.php/$2 [L]
Budget101
08-07-2008, 06:37 PM
here's a Link on how to do a Redirect:
http://www.vbulletin.com/forum/showthread.php?t=247241
and also to redirect from 1 forum to another:
http://www.vbulletin.com/forum/showthread.php?t=247216
hth
(And Mod's if linking to vb.com isn't allowed, would someone give me a holler and let me know! Thnx)
sockwater
08-07-2008, 10:10 PM
It's adding the .php because you have .php in your rewrite rule. No mystery about it. :)
Give me an example URL that you want to permanently redirect to another URL and I'll give you the rewrite rule.
davide101
08-08-2008, 12:10 AM
Sockwater, I did a poor job explaining the problem. I'm not as slow as I look, I promise. :) I'm working with someone else's code and trying to understand exactly what's going wrong.
I have a file called headlines.php. With the .htaccess posted above, you can access it via:
http://www.diabetesdaily.com/news/headlines.php OR
http://www.diabetesdaily.com/news/headlines/.
Or you could access:
http://www.diabetesdaily.com/news/headlines/page/1 OR
http://www.diabetesdaily.com/news/headlines.php/page/1
If I make this a 301 redirect it goes to 404. If I remove the .php from the .htaccess file, I get a server error. If I add a 301 redirect and remove the .php, it goes to 404.
Ideally, I think I want to make the last line a 301 redirect AND redirect from headlines.php to headlines.
Is this more clear? I feel like I can follow the current .htaccess, but I'm at a total loss how to describe what I want to happen.
sockwater
08-08-2008, 03:22 AM
I wasn't trying to imply you were slow.. :)
I would do something like this, but it's kind of hard to tell, not knowing how your scripts work.
# permanently redirect headlines.php to headlines/ (change the url)
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^news/headlines.php$ headlines/ [L,R=301]
# send the headlines/ url to the headlines.php script behind the scenes (don't change url)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^headlines/(.*)$ headlines.php?uri=$1 [L]
davide101
08-08-2008, 12:45 PM
That works perfectly for my specific example. Using my own brain power, I'm going to make a generic edition of that rewrite. Thanks for the assistance!
sockwater
08-08-2008, 01:43 PM
To make it more generic, while still controlling the input, you could try something like this:
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^news/(headlines|otherscript|yetanother).php$ $1/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(headlines|otherscript|yetanother)/(.*)$ $1.php?uri=$2 [L]
:)
davide101
08-08-2008, 04:02 PM
I got it working. We've been bouncing between the 5 and 7 spots on Google for "diabetes news" but have thousands of incoming links pointing at three different URLS. By consolidating them into one, we hope to jump towards number one. :) Thanks very much for your help as always.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.