Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting variable from pretty url

I've done things very similar before but for some reason I'm having a little difficulty with the specific scenario. I want to pass a folder path as a variable and make it look pretty.

I have a working url like:

http://mysite.com/albums/index.php?p=folder/subfolder/

I can view it without the 'index.php' like:

http://mysite.com/albums/?p=folder/subfolder/

What I want is a pretty url that looks like this:

http://mysite.com/albums/folder/subfolder/

Basically, anything after /albums/ should be a single variable. I've played with my .htaccess RewriteRule a bunch and can't seem to get it working. (get 404 errors) This is what I currently have:

RewriteEngine On
RewriteRule ^albums/(.*)$ albums/?p=$1
like image 255
Chris Avatar asked Mar 28 '26 02:03

Chris


1 Answers

below is what i use though every call is directed to my index.php file and from there i do anything with it

  Options +FollowSymLinks
  RewriteEngine On

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

  RewriteRule ^.*$ ./index.php

Hope it helps

like image 125
omoabobade Avatar answered Mar 29 '26 20:03

omoabobade