Ahmar Ali
Ahmar Ali

Reputation: 1068

Apache PHP rewrite multiple query string variables

I am very new to apache and mod re-write I am trying to make pretty links using .htaccess. My URL looks like this:

http://example.com/single_picture.php?name=Testing-123&cat_id=1

I want to make it look like

http://example.com/pictures/Testing-123/

That is just the name. Here is what I have put in my .htaccess file but it is not working.

Options +FollowSymLinks
RewriteEngine On


    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{SCRIPT_FILENAME} !-f

    RewriteRule ^pictures/(\s+)*$ ./single_picture.php?name=$1&cat_id=$2

How do I do it? Ahmar

Upvotes: 0

Views: 78

Answers (1)

Michael Smith
Michael Smith

Reputation: 665

Try This:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^pictures/([A-Za-z0-9\-_]+)/([A-Za-z0-9\-_]+)/?$ /single_picture.php?name=$1&cat_id=$2

Also remember that a rewrite will not rewrite the request a user has made. i.e. http://example.com/single_picture.php?name=Testing-123&cat_id=1 will work as will http://example.com/pictures/Testing-123/1/.

You will need to make the user view the page via the SEO link by changing the links on your website to reflect this.

Upvotes: 1

Related Questions