User Name
Password
AppleNova Forums » Programmer's Nook »

Apache 301 Redirect to Hide PHP garbage


Register Members List Calendar Search FAQ Posting Guidelines
Apache 301 Redirect to Hide PHP garbage
Thread Tools
drewprops
Space Pirate
 
Join Date: May 2004
Location: Atlanta
 
2012-03-15, 14:55

I recently made the mental leap to understanding how to serve up URLs to mod_rewrite so that I have pretty URLs in some of my simple websites.

I need some help though, when it comes to using a 301 Redirect to 'clean up' the URL when people hit the website from an old PHP-encrusted link.


For example:

Suppose that someone clicks an old-fashioned URL to our site, and that the page still exists at:

Code:
example.com/index.php?x=foo
but we want it to look like this:

Code:
example.com/foo
in their browser's navigation bar, as it does when clicked upon from any navigation links internal to this website.


I thought that using a redirect in this fashion:

Code:
Redirect 301 /index.php?x=foo http://example.com/foo

would work just fine, but of course it does not.


Any insight you folks could provide would be appreciated.

...

Steve Jobs ate my cat's watermelon.
Captain Drew on Twitter
  quote
turtle
Lord of the Rant.
Formerly turtle2472
 
Join Date: Mar 2005
Location: Upstate South Carolina
 
2012-03-15, 16:13

Shouldn't it be a rewrite rule? I'm not great to .htaccess but this seems like what it should be.

Code:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
This is for WP that makes the index.php go away. It's going to be more like this.

Louis L'Amour, “To make democracy work, we must be a nation of participants, not simply observers. One who does not vote has no right to complain.”
Visit our archived Minecraft world! | Maybe someday I'll proof read, until then deal with it.
  quote
turtle
Lord of the Rant.
Formerly turtle2472
 
Join Date: Mar 2005
Location: Upstate South Carolina
 
2012-03-15, 16:19

This site says to do this:
Code:
Options +FollowSymLinks RewriteEngine on RewriteRule /x/(.*) index.php?x=$1
Though you might want to remove the "/x" to fit your request.
  quote
drewprops
Space Pirate
 
Join Date: May 2004
Location: Atlanta
 
2012-03-15, 16:33

Oh now I've got the rewrite working, that part is EASY....

Code:
Options +FollowSymLinks RewriteEngine on RewriteRule ^/?([a-zA-Z_0-9\s]+)$ index.php?x=$1 [L]

It's the redirect of a specific "old-fashioned" link that I'm wanting to fix.
I don't even want the visitor to end up SEEING the ugly PHP code, even if they clicked such a link.



...

Steve Jobs ate my cat's watermelon.
Captain Drew on Twitter
  quote
Posting Rules Navigation
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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

Post Reply

Forum Jump
Thread Tools
Similar Threads
Thread Thread Starter Forum Replies Last Post
Need a redirect page turtle Programmer's Nook 3 2009-06-07 18:33
Redirect non-www traffic to www? turtle Programmer's Nook 3 2008-11-09 16:15
Garbage in Google's "Sponsored Links". Wtf? Brad General Discussion 8 2008-08-04 12:41
Microsoft code garbage? alexluft Third-Party Products 10 2005-04-28 10:05
PHP & Apache 2 ast3r3x Genius Bar 0 2005-03-16 20:38


« Previous Thread | Next Thread »

All times are GMT -5. The time now is 14:41.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004 - 2024, AppleNova