Reputation: 9230
I've a gallery which should display different albums of pictures.
When I open the gallery with the link, I add the album name with PHP:
<a href="gallery/index.php?album=nature
Then I get the album name with $_GET['album']
. It works fine.
But for Me is a clean URL important. And when I am finished with the site and upload it to a hoster, then I change the URL "layout" with the .htaccess file.
So the URL http://www.example.com/gallery/index.php?album=blacknwhite
change to http://www.example.com/gallery/
.
Now I think with the new URL, $_GET
doesn't work anymore. Is there a alternative to $_GET to hand over the album name?
Here's again the code sample:
Site with the link:
<a href="gallery/index.php?album=nature">D</a>
index.php the PHP part:
<head>
<?PHP
$album = $_GET['album'];
?>
</head>
Upvotes: 3
Views: 4291
Reputation: 1041
Yes there is another way but its not recommended. look at http://php.net/manual/en/reserved.variables.server.php you can use $_SERVER. but the correct way is using RewriteRule that well explained here: http://www.webdeveloper.com/forum/showthread.php?214564-RewriteRule-with-GET-data
Upvotes: 0
Reputation: 2678
I would recommend you to keep relevant information in your URL, and the album-title seems relevant in this case as I assume the page is centralized around it?
Make your URL work like this instead:
http://www.example.com/gallery/<album-title>/
Since you already seem to know how to use htaccess, rewrite the URL to your "ugly" one there if you get this type of format. Your URL will look way much better then.
http://www.example.com/gallery/blacknwhite/
Upvotes: 3
Reputation: 17885
Your rule should look something like:
RewriteRule ^/([a-z]+)/?$ get_product_by_name.php?product_name=$1 [L]
It should not affect $_GET at all, so if it is not working it's because your rule is not setup correctly.
Upvotes: 3