简体   繁体   中英

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]

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]

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.

Try this. only one line :)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM