Jump to content

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 :)

Edited by Johns3n

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.