Jump to content

How To Handle Xx Amount Of Slashes In A Rewritten Url.


Johns3n

Recommended Posts

Hello PHPFreaks :)

 

Been a long time since i've been here last time! (hopefully it means that i'm getting better :)

 

However!

 

I'm playing around with "new" technology the mod_rewrite for the .htaccess file.

 

I'm writting a php app where the url has 2 parameters.

 

example.com?path=this/is/a/path/to/this/&slug=page

 

NOW my dilemma is that my .htaccess rules work IF there is NO / (slash) in the ?path= var (since I separate the 2 vars at a /).

 

my question is now! (bear in mind here that i'm a ROOKIE at .htaccess rewriting) how do i go about in the .htaccess file to make it reconize that whatever comes after the last slash the $2 variable and everything is $1 - even if there is no $path defined in the url?

 

BTW! I'm not looking for free handouts and do my coding here! I'm willing to learn here but just need pointers!! :)

 

I've pasted my .htaccess file here:

 

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/index.php
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)$ /index.php?slug=$1&type=$2&view=$3&action=$4 [L,PT]
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)$ /index.php?slug=$1&type=$2&view=$3 [L,PT]
RewriteRule ^([^/.]+)/([^/.]+)$ /index.php?path=$1&slug=$2 [L,PT]
RewriteRule ^([^/.]+)$ /index.php?slug=$1 [L,PT]
RewriteRule ^(.+)/$ /$1 [R=301,L]

 

Thanks in advance :)

It could also even just be:

 

example.com/page

 

So it just uses the ?slug=page variable and the first ?path=something variable is just defined as:

 

if(!isset($_GET['path'])){ $_GET['path'] = NULL; }

 

in the PHP app.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.