I need help rewriting the URLs generated dynamically by a PHP photo gallery script. The following examples are how the URLs currently show on the browser: index.php?page=list-image&album=1 (The URL of "album 1" while I name the album "Tropical Islands") and index.php?page=list-image&album=2 (The URL of "album 2 while the name might be something like " Exotic Beaches" or "Beaches"). I need help to make the above-mentioned "album 1" URL to be: "Tropical_Islands/" and other albums to be in this form. The following example is how the image URLs shows: index.php?page=image-detail&album=1&image=1 (The URL of "image 1" of "album 1" while I name this image "Buddha Temple") I want the image URLs to be in this form: "Tropical_Islands/Buddha_Temple/" Can anyone please show me how to rewrite the album and image URLs in order to have search engine-friendly URLs. I have tried without success to achieve this. This is what I have done so far: ## mod_rewrite configuration Options +FollowSymLinks # Turn on the rewriting engine RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC] RewriteRule \.(gif|jpg|png)$ - [F] RewriteRule ^[a-zA-Z]$ index.php?page=list-image&album=$0 RewriteRule ^([a-zA-Z])\/$ /$1 [R] RewriteRule ^([A-Z]+)([a-z)]+)([0-9)]+)\.html$ index.php?page=image-detail&album=1&image=$3 RewriteRule ^([^/]+)/$ index.php?page=image-detail&album=1&image=$1 #Options -Indexes IncludesNOEXEC FollowSymLinks Code (markup): Any help will be so much appreciated.
First, you'll have to check if your mod_rewrite module is enabled. You can check this by creating a phpinfo.php file at your server's root : <? phpinfo(); ?> PHP: point your browser to this file and look at the loaded modules. NOTE : do NOT store this file too long on your server!!!! After viewing it, print out the output and delete the phpinfo.php! Come back then and let us know if your mod_rewrite engine is ON.
OK, then try to test it! create a test.html : <h2>This is the HTML file.</h2> Code (markup): and create a test.php: <h2>This is the PHP file.</h2> PHP: Upload them both to your server. Create a .htaccess file (you can use Notepad, save as .htaccess, BUT not "filename.htaccess", just ".htaccess") : RewriteEngine on RewriteRule ^/?test\.html$ test.php [L] Code (markup): upload it to your server's root. Point your browser to test.html If everything is OK, you should see This is the PHP file Code (markup): while your browser is showing test.html at the location box. If that is working, you should write the rewrite rule! Let me know and I'l try to help you. Good luck!
I know Mod_Rewrite works on my hosting account, because I own other sites there that utilize it. The thing is that I wasn't the person who wrote those ones - the .htaccess files. I know exactly where to place this new one, but writing it is the issue. This new htaccess file is meant for a new site I want to add. Coding the right Mod_Rewrite is my problem. I do appreciate your time and effort, and seeing me through will be a thing to remember for a long time.
I see. Well, I can't make your rewrite rule work correctly and for the right purpose, but I'd like to help you so you can do it for yourself. Writing 'rewrite rules' are not as complicated as it may see, I believe you'll solve this issue in less than an hour. A great tutorial for rewrite_rules is located at : http://www.addedbytes.com/apache/url-rewriting-for-beginners/ or http://www.workingwith.me.uk/articles/scripting/mod_rewrite
I have been through addedbytes tutorials a cheat sheets several times. I guess I have to settle down and learn regular expressions properly. Thanks for your time!
I still can't get this mod_rewrite to work. Can someone please give me a helping hand? This is what I have as of now: ## mod_rewrite configuration Options +FollowSymLinks # Turn on the rewriting engine RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC] RewriteRule \.(gif|jpg|png)$ - [F] RewriteRule ^([a-zA-Z_]+)$ index.php?page=list-image&album=$1 [L] RewriteRule ^([a-zA-Z_]+)/([a-zA-Z_]+)\.html$ index.php?page=image-detail&album=$1&image=$2 [L] #Options -Indexes IncludesNOEXEC FollowSymLinks Code (markup): When I try http://www.mydomain.com/Tropical_Islands , only the page Header loads and this error message appears: Error, get album name failed. Unknown column 'Tropical_Islands' in 'where clause' Code (markup):