Fabien
Fabien

Reputation: 11

Url Rewrite doesn't work on apache server godaddy

I host my website on a godaddy webserver and i try to use htaccess file to rewrite some urls but it doesn't work. Help would be very appreciated.

Basically I would like to replace an url like:

/photographers/photographer.php?id=1&name=john-doe

in:

/photographer/john-doe

Obviously I would like also my server to redirect internally in the opposite way.

I tried the following code in my .htaccess.

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule    ^photographer/([A-Za-z-]+)/?$ photographers/photographer.php?id=$2&name=$1 [NC,L]

Upvotes: 0

Views: 87

Answers (3)

Meskan
Meskan

Reputation: 79

Try this. only one line :)

RewriteRule ^(photographer)/(.*)$ /photographers/photographer.php?id=1&name=$2 [L]

Upvotes: 0

Croises
Croises

Reputation: 18671

You can't do that without ID.

Add id in the url:

/photographer/john-doe/1

And that .htaccess:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^photographer/([A-Za-z-]+)/(\d+)/?$ photographers/photographer.php?id=$2&name=$1 [NC,L]

Upvotes: 1

BritishWerewolf
BritishWerewolf

Reputation: 3968

You need to use the Query String Append flag (QSA)

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^photographer/([A-Za-z-]+)/?$ photographers/photographer.php?id=$2&name=$1 [QSA,NC,L]

You could also try removing the RewriteBase line to see if that helps too.

Upvotes: 0

Related Questions