.htaccess problem

  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

I am having trouble with my .htaccess file and rewriting ... this shouldn't be too tough, I am just really no good at it.

I have the following .htaccess file
Code: [ Select ]
RewriteEngine On

RewriteRule ^(.*)/(.*)/(.*).html$ $1/$2.php?data=$3 [L]
RewriteRule ^(.*)/(.*).html$         $1/$2.php [L]
RewriteRule ^(.*).html$             $1.php [L]
  1. RewriteEngine On
  2. RewriteRule ^(.*)/(.*)/(.*).html$ $1/$2.php?data=$3 [L]
  3. RewriteRule ^(.*)/(.*).html$         $1/$2.php [L]
  4. RewriteRule ^(.*).html$             $1.php [L]


But when I go to the page http://nmc.bong/member/view/3.html I get the following error:
Code: [ Select ]
You don't have permission to access /redirect:/member/view.php.php.php on this server.


Just for extra information, "member" is a folder and "view" is a php page called "view.php" and then one GET variable is passed to it, "data" ...

Can anyone please tell me what I'm doing wrong here?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Brenden
  • Born
  • Born
  • Brenden
  • Posts: 3

Post 3+ Months Ago

Instead of using (.*) you should use more specific fields like ([a-zA-Z]*) and ([0-9]*), because (.*) includes forward slashes. Also I think your redirect locations should be more specific like /$1/$2.php?data=$3
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6252
  • Loc: Seattle, WA

Post 3+ Months Ago

Code: [ Select ]
RewriteEngine On
 
RewriteRule ^(.*)/(.*)/(.*)\.html$    $1/$2.php?data=$3 [L]
RewriteRule ^(.*)/(.*)\.html$         $1/$2.php [L]
RewriteRule ^(.*)\.html$              $1.php [L]
  1. RewriteEngine On
  2.  
  3. RewriteRule ^(.*)/(.*)/(.*)\.html$    $1/$2.php?data=$3 [L]
  4. RewriteRule ^(.*)/(.*)\.html$         $1/$2.php [L]
  5. RewriteRule ^(.*)\.html$              $1.php [L]


Gotta escape those dots.
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

Thanks a million. I'm not sure how I forgot that ... hehe ... thanks ... both of your inputs put me on the right track together ... WooT!
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

Okay I have another issue, with the following line:
Code: [ Select ]
RewriteRule ^([a-zA-Z0-9])/([a-zA-Z0-9])/([a-zA-Z0-9])\.html$ $1/$2.php?data=$3 [L]

when I print ou my GET variables using pre tags I get the following:
Code: [ Select ]
Array
(
)
  1. Array
  2. (
  3. )

Why would this happen?
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

Change "[L]" to "[L,QSA]" which stands to "Query String Append".
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

Unfortunately still exactly the same result ... so at this moment I am looking at http://nmc.bong/member/view/3.html and I have the following rewriterule:
Code: [ Select ]
RewriteRule ^([a-zA-Z0-9])/([a-zA-Z0-9])/([a-zA-Z0-9])\.html$ $1/$2.php?data=$3 [L,QSA]

and still I am getting the following when printing out my GET variable like this:
Code: [ Select ]
echo "<pre>" . print_r($_GET,1) . "</pre>";

the output:
Code: [ Select ]
Array
(
)
  1. Array
  2. (
  3. )
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

oh and obviously the .bong extension won't exist for you, this is a local demo-site ...
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

Okay, there's more than that wrong, oh my, let me quickly explain what I have done and what I'd like to achieve, and maybe it would make more sense then ...

I have the following folder structure:
  • index.php
  • member(Folder)
    • add.php
    • view.php
    • delete.php
  • profile_holder(Folder)
    • add.php
    • view.php
    • delete.php

And I'd like to have the following URLs ...
nmc.bong/member/add.html ... goes to nmc.bong/member/add.php
nmc.bong/member/view/1.html ... goes to nmc.bong/member/view.php?data=1
nmc.bong/member/delete/1.html ... goes to nmc.bong/member/delete.php?data=1

nmc.bong/profile_holder/add.html ... goes to nmc.bong/profile_holder/add.php
nmc.bong/profile_holder/view/1.html ... goes to nmc.bong/profile_holder/view.php?data=1
nmc.bong/profile_holder/delete/1.html ... goes to nmc.bong/profile_holder/delete.php?data=1

nmc.bong/home.html ... goes to nmc.bong/index.php?data=home
nmc.bong/about_us.html ... goes to nmc.bong/index.php?data=about_us

How would I achieve this?
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

Okay I am going to try again, I am not winning with this. My folder structure is still as it is in the post above, and my .htaccess file looks like follows:
Code: [ Select ]
RewriteEngine On

RewriteRule ^([a-zA-Z0-9])/([a-zA-Z0-9])/([a-zA-Z0-9])\.html$     $1/$2\.php?data=$3 [L,QSA]
RewriteRule ^([a-zA-Z0-9])/([a-zA-Z0-9])\.html$                         $1/$2\.php [L]
RewriteRule ^([a-zA-Z0-9])\.html$                                 $1\.php [L]
  1. RewriteEngine On
  2. RewriteRule ^([a-zA-Z0-9])/([a-zA-Z0-9])/([a-zA-Z0-9])\.html$     $1/$2\.php?data=$3 [L,QSA]
  3. RewriteRule ^([a-zA-Z0-9])/([a-zA-Z0-9])\.html$                         $1/$2\.php [L]
  4. RewriteRule ^([a-zA-Z0-9])\.html$                                 $1\.php [L]


I have uploaded the site to a live server here ...
The URLs I am having trouble with are the following ones:

http://www.nmcfashion.co.za/member/add.html ... which should go to http://www.nmcfashion.co.za/member/add.php

http://www.nmcfashion.co.za/member/view/3.html ... which should go to http://www.nmcfashion.co.za/member/view.php?data=3

http://www.nmcfashion.co.za/login.html ... which should go to http://www.nmcfashion.co.za//login.php

If those work the rest will work, but I can't seem to get this working.

Post Information

  • Total Posts in this topic: 10 posts
  • Users browsing this forum: No registered users and 151 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.