Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1694 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Business and Website Management     Advertising, SEO and Social Marketing :

Mod Rewrite Problem

Thread title: Mod Rewrite Problem
Closed Thread  
Page 1 of 2 1 2 >
    Thread tools Search this thread Display Modes  
01-25-2006, 05:57 PM
#1
buddybuddha is offline buddybuddha
buddybuddha's Avatar
Status: Junior Member
Join date: Jan 2006
Location:
Expertise:
Software:
 
Posts: 84
iTrader: 0 / 0%
 

buddybuddha is on a distinguished road

Send a message via AIM to buddybuddha

  Old  Mod Rewrite Problem

Im completely new to mod rewrite and this is what i pieced together from what I have read in tutorials:

Code:
#start .htaccess code
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^/src/artist.php?artist\=([^&]+)\&song\=([^&]+)$
RewriteRule ^$ /artists/%1-%2.html [R=301,L]
The problem is that it doesnt do what I want it to. I have a script on my site so that:

http://www.bluntbeat.com/src/artist....=jimmy&song=01
will just display the two variables.
I want to have it so that:
http://www.bluntbeat.com/artists/jimmy-01.html
points to the same thing.

Whats wrong with my code? Thanks in advanced.

01-26-2006, 05:42 PM
#2
Marky is offline Marky
Status: Ready for Action
Join date: Aug 2005
Location: UK
Expertise:
Software:
 
Posts: 2,775
iTrader: 14 / 100%
 

Marky is on a distinguished road

  Old

If you mean the problem is that it's a 404 page, this is because your host has installed 'mod_rewrite' support.
Just open up a ticket or ask them nicely to install it and it should work right

01-26-2006, 06:10 PM
#3
Aros is offline Aros
Aros's Avatar
Status: Lurker
Join date: Jul 2004
Location: the Netherlands
Expertise:
Software:
 
Posts: 1,074
iTrader: 2 / 100%
 

Aros is on a distinguished road

  Old

Try this:
Code:
RewriteEngine on
Options +FollowSymLinks

RewriteRule ^([A-Za-z0-9\-]+)-([0-9]+).html$ /src/artist.php?artist=$1&song=$2 [L]

01-27-2006, 02:58 AM
#4
buddybuddha is offline buddybuddha
buddybuddha's Avatar
Status: Junior Member
Join date: Jan 2006
Location:
Expertise:
Software:
 
Posts: 84
iTrader: 0 / 0%
 

buddybuddha is on a distinguished road

Send a message via AIM to buddybuddha

  Old

It didnt work either way and the host said its installed. Are you sure the syntax is right?

01-27-2006, 03:05 AM
#5
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

You have to be careful to escape dots in the regular expression (eg, .html should be \.html) since the dot character is a RE special character.

01-27-2006, 04:35 AM
#6
buddybuddha is offline buddybuddha
buddybuddha's Avatar
Status: Junior Member
Join date: Jan 2006
Location:
Expertise:
Software:
 
Posts: 84
iTrader: 0 / 0%
 

buddybuddha is on a distinguished road

Send a message via AIM to buddybuddha

  Old

Code:
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^/src/artist\.php?artist\=([^&]+)\&song\=([^&]+)$
RewriteRule ^$ /artists/%1-%2\.html [R=301,L]
This is what I have now, but it still gives me a 404. Can anyone give me a real quick example that is very simple so that I can test the system.

01-27-2006, 01:58 PM
#7
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

The way that you're doing things, if someone tries to access http://yoursite.com/src/artist.php?artist=foo&song=bar the server will look for http://yoursite.com/artists/foo-bar.html which does not exist.

You'll need to work the other way around, if someone tries to get to the .html page, the server should redirct them to the .php page.

01-27-2006, 02:03 PM
#8
Marky is offline Marky
Status: Ready for Action
Join date: Aug 2005
Location: UK
Expertise:
Software:
 
Posts: 2,775
iTrader: 14 / 100%
 

Marky is on a distinguished road

  Old

Originally Posted by Salathe
The way that you're doing things, if someone tries to access http://yoursite.com/src/artist.php?artist=foo&song=bar the server will look for http://yoursite.com/artists/foo-bar.html which does not exist.

You'll need to work the other way around, if someone tries to get to the .html page, the server should redirct them to the .php page.
But he needs to be able to keep the html part, maybe because of SEO?

01-27-2006, 04:46 PM
#9
aSAPcreations is offline aSAPcreations
aSAPcreations's Avatar
Status: I love this place
Join date: Dec 2005
Location: Pennsylvania USA
Expertise:
Software:
 
Posts: 565
iTrader: 1 / 100%
 

aSAPcreations is on a distinguished road

Send a message via AIM to aSAPcreations Send a message via MSN to aSAPcreations

  Old

I think its something like this. I dont use .htaccess alot but if you finish this I think it will do what you want.
PHP Code:
RewriteEngine On

RewriteCond 
%{QUERY_STRING} !artist
RewriteCond 
%{REQUEST_FILENAME} !^(/src/artist)\.php$
RewriteRule (something here).html$ /src/artist.php?artist=(something here) [R=301,L

01-27-2006, 06:41 PM
#10
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

I just tried the following setup and everything worked fine. In a single folder, I had the following files: .htaccess and test.php

.htaccess
Code:
RewriteEngine on
Options +FollowSymLinks
RewriteRule ([A-Za-z0-9\-]+)-([0-9]+).html$ test.php?artist=$1&song=$2 [L]
test.php
PHP Code:
<?php

echo $_SERVER['QUERY_STRING'];

?>
When I tried to access quick-007.html in that directory (which obviously doesn't exist), Mod_Rewrite successfully forwarded the request to the PHP script which echoed as expected:
Code:
artist=quick&song=007

Closed Thread  
Page 1 of 2 1 2 >


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed