Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 08-07-2008, 02:38 PM
davide101 davide101 is offline
 
Join Date: Dec 2005
Posts: 100
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default .htaccess riddle - guru needed!

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.

Code:
RewriteEngine On
RewriteBase /news/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/]+)/?(.*)      $1.php/$2       [L]
Reply With Quote
  #2  
Old 08-07-2008, 06:37 PM
Budget101 Budget101 is offline
 
Join Date: Jul 2008
Posts: 331
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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)
Reply With Quote
  #3  
Old 08-07-2008, 10:10 PM
sockwater's Avatar
sockwater sockwater is offline
 
Join Date: Apr 2008
Posts: 187
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 08-08-2008, 12:10 AM
davide101 davide101 is offline
 
Join Date: Dec 2005
Posts: 100
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 08-08-2008, 03:22 AM
sockwater's Avatar
sockwater sockwater is offline
 
Join Date: Apr 2008
Posts: 187
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.

Code:
# 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]
Reply With Quote
  #6  
Old 08-08-2008, 12:45 PM
davide101 davide101 is offline
 
Join Date: Dec 2005
Posts: 100
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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!
Reply With Quote
  #7  
Old 08-08-2008, 01:43 PM
sockwater's Avatar
sockwater sockwater is offline
 
Join Date: Apr 2008
Posts: 187
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

To make it more generic, while still controlling the input, you could try something like this:

Code:
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]
Reply With Quote
  #8  
Old 08-08-2008, 04:02 PM
davide101 davide101 is offline
 
Join Date: Dec 2005
Posts: 100
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:34 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04292 seconds
  • Memory Usage 2,222KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete