I need help with redirect+rewrite url

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
prue_
Forum Commoner
Posts: 64
Joined: Thu May 07, 2009 10:34 pm

I need help with redirect+rewrite url

Post by prue_ »

how to write .htaccess??? to redirect some url then rewrite it into SEO friendly url??
e.g olpage.php?subfolder=12 to newpage.php/subfolder/12.html

thanks a lot!
insight
Forum Commoner
Posts: 52
Joined: Tue Jul 07, 2009 9:12 am

Re: I need help with redirect+rewrite url

Post by insight »

Something like this?

Code: Select all

RewriteEngine On
RewriteCond %{HTTP_HOST} olpage.php?subfolder=12 [nc]
RewriteRule (.*) newpage.php/subfolder/12.html [R=301,L]
The code is probably done wrong, but it's somehting like that I think.
prue_
Forum Commoner
Posts: 64
Joined: Thu May 07, 2009 10:34 pm

Re: I need help with redirect+rewrite url

Post by prue_ »

if i have a lot of page to redirect and rewrite, will I just have to add all of them??

if I'm not mistaken, is this the one for redirect???

RewriteCond %{HTTP_HOST} olpage.php?subfolder=12 [nc]
and this one for rewrite???

RewriteRule (.*) newpage.php/subfolder/12.html [R=301,L]

Thanks!
prue_
Forum Commoner
Posts: 64
Joined: Thu May 07, 2009 10:34 pm

Re: I need help with redirect+rewrite url

Post by prue_ »

what could be wrong with the script above?? it doesn't seem to be working?? thanks!
insight
Forum Commoner
Posts: 52
Joined: Tue Jul 07, 2009 9:12 am

Re: I need help with redirect+rewrite url

Post by insight »

prue_ wrote:what could be wrong with the script above?? it doesn't seem to be working?? thanks!
Yea mate, I figured it might be wrong :).
Just visit this site. It should help you
prue_
Forum Commoner
Posts: 64
Joined: Thu May 07, 2009 10:34 pm

Re: I need help with redirect+rewrite url

Post by prue_ »

I used the ff. code but it's not working... what's wrong with this code?? thanks!

Code: Select all

# Enable Rewrite Engine
RewriteEngine on
 
#Redirect old.php to new.html
Redirect 301 /old.php long_ugly_url.php?something=yes
 
 
#Create friendly URL
RewriteRule ^something_short.html$ long_ugly_url.php?something=yes [L]
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: I need help with redirect+rewrite url

Post by cpetercarter »

Before trying to get the code right, have you checked that you can in fact use an .htaccess file on your server? Two things are important:
- the Apache module mod_rewrite must be loaded
- the relevant Apache configuration file must permit "override"

You can use phpinfo() to check whether mod_rewrite is loaded - look for the "loaded modules" box under "apache2handler".

A good way to check if Apache is able to read .htaccess files is to write a garbage file (put a random selection of characters into it) and load it to your site. You should get an "internal server error" message when you try to access the site. If you don't, Apache isn't reading the .htaccess file.

You need root access to the server to load mod_rewrite or to enable "override".
Post Reply