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
https://forums.phpfreaks.com/topic/195579-wierd/
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
https://forums.phpfreaks.com/topic/195579-wierd/#findComment-1027668
Share on other sites

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.