www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] Apache2 htaccess rewrite issue

Hybrid View

  1. #1
    Join Date
    Dec 2011
    Posts
    3

    resolved [RESOLVED] Apache2 htaccess rewrite issue

    I'm just recovering from reformatting my computer and it turns out I forgot to backup my backups, and the inevitable happened. I accidentally overwrote my .htaccess file which for the life of me I can't recreate it.

    I use ?p= to dictate what to display in the page and I used rewrite to mask domain.com/?p=foo/bar as domain.com/foo/bar/, and now the entire site is un-navigatable. I've been messing around for the best part of an hour and I can't seem to get it right. Can anyone furnish me with the right answer?

  2. #2
    Join Date
    Dec 2005
    Posts
    2,984
    Code:
    RewriteEngine on
    RewriteRule ^(.*)/?$ index.php?p=$1 [L]
    Last edited by aj_nsc; 12-04-2011 at 07:14 PM.

  3. #3
    Join Date
    Dec 2011
    Posts
    3
    That almost works perfectly!

    What you've suggested seems to act as ?p=foo/bar/ which adds an extra, empty value to the array ([0]=>'foo', [1]=>'bar', [2]=>''), unlike what I had before which left me with just ?p=foo/bar ([0]=>'foo', [1]=>'bar'). Not a huge issue, I can get around it.

    Also, I seem to remember there was something involving -f or -d, which prevented the rule applying to directories, which allowed me to visit domain.com/images/ which is an actual folder, not a page on the site. (?p=images).

    Hoping what I've written makes sense, a storming headache, a technical accident and a sudden realisation you're an idiot does not make for a good poster.

  4. #4
    Join Date
    Dec 2005
    Posts
    2,984
    Code:
    RewriteCond %{REQUEST_FILENAME} !-d
    This (place just below RewriteEngine On) will prevent RewriteRules on any URLs that match actual directories .

    Google could have provided you with all these answers.

    .htaccess mod_rewrite

  5. #5
    Join Date
    Dec 2011
    Posts
    3
    I tirelessly searched Google to no avail, this place is usually my last resort. Thanks for your help though. As it turns out, after some fiddling, what I actually needed was this.

    Code:
    	RewriteEngine on
    	RewriteCond %{REQUEST_FILENAME} !-f
    	RewriteCond %{REQUEST_FILENAME} !-d
    	RewriteRule ^(.*)/$ index.php?p=$1 [L,NC]
    God help me, I've little idea what it means, but it serves its purpose. Thanks for your help.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles