|
|
|
|
Thread title: Mod Rewrite Problem |
|
|
|
|
|
Thread tools
Search this thread
Display Modes
|
|
01-25-2006, 05:57 PM
|
#1
|
Status: Junior Member
Join date: Jan 2006
Location:
Expertise:
Software:
Posts: 84
|
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
|
Status: Ready for Action
Join date: Aug 2005
Location: UK
Expertise:
Software:
Posts: 2,775
|
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
|
Status: Lurker
Join date: Jul 2004
Location: the Netherlands
Expertise:
Software:
Posts: 1,074
|
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
|
Status: Junior Member
Join date: Jan 2006
Location:
Expertise:
Software:
Posts: 84
|
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
|
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
Posts: 3,820
|
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
|
Status: Junior Member
Join date: Jan 2006
Location:
Expertise:
Software:
Posts: 84
|
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
|
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
Posts: 3,820
|
|
|
01-27-2006, 02:03 PM
|
#8
|
Status: Ready for Action
Join date: Aug 2005
Location: UK
Expertise:
Software:
Posts: 2,775
|
Originally Posted by Salathe
|
But he needs to be able to keep the html part, maybe because of SEO?
|
|
01-27-2006, 04:46 PM
|
#9
|
Status: I love this place
Join date: Dec 2005
Location: Pennsylvania USA
Expertise:
Software:
Posts: 565
|
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
|
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
Posts: 3,820
|
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
|
|
|
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|