Jump to content

Wierd!!!


JonnoTheDev

Recommended Posts

I'm not the greatest when it comes to more complex rewrite rules so here goes. My directory structure is similar to:

(/docs is the document root)

docs/index.php

docs/file1.php

docs/sitefiles/index.php

docs/sitefiles/file1.php

docs/sitefiles/file2.php

 

And so on. OK, here's the issue. I am trying to backref a url parameter that is sent to the index.php file within the sitefiles subdir for example

http://mydomain.com/sitefiles/foobar.com

http://mydomain.com/sitefiles/foobar.co.uk

 

The domain at the end is the param I need to capure. The original url is something like:

http://mydomain.com/sitefiles/index.php?url=foobar.co.uk

 

So, my .htaccess sits in the sitefiles directory and looks like

RewriteEngine On
RewriteRule ^([a-z-]+\.[a-z]{2,}\.?[a-z]{0,})$ index.php?url=$1 [L]

But when I try this the value contained in $_GET['url'] is index.php. Wierd.

Link to comment
Share on other sites

Most likely what is happening is the .htaccess is being accessed twice (which is not uncommon) so the first rewrite runs fine, but then it is re-directed and runs through the rules again and since index.php matches your ruleset it is ran again and index.php is now appended.

 

The fix, make the rewrite rule omit .php, or add a rule above it that index.php is left alone like:

RewriteEngine On
RewriteRule ^index.php$ - [L] # Leave index.php to itself
RewriteRule ^([a-z-]+\.[a-z]{2,}\.?[a-z]{0,})$ index.php?url=$1 [L]

 

Not sure if that will work, given the index.php to itself rule, but you should be able to modify it / work from that.

Link to comment
Share on other sites

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.