Welcome Guest, Not a member yet? Register   Sign In
The URI you submitted has disallowed characters: $1
#1

[eluser]Takapaka[/eluser]
Hi ,

I know it has been discussed here hundreds times but honestly I haven't found the solution here.

The problem basically is - my route with variables gives me the

"The URI you submitted has disallowed characters: $1" error.

I tried all htaccess configurations that I found on this forum.
In the route i tried " and I tried ' - nothing works.

I guess this is somehting basic and should work. Or is the routeing so complex that only the most advanced users can use it.

my route:

$route['(:any)/(:any)'] = "gifts/users_gifts_public/$1/$2";

my htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|ads|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
#2

[eluser]BrianDHall[/eluser]
Hm, perhaps:

Code:
$route['(:any)'] = "gifts/users_gifts_public/$1;

Might work more like you expect. :any would match anything, including the /, so :any/:any won't work right.
#3

[eluser]Takapaka[/eluser]
Actually to beter ilustrate please have a look at this line>

$route[’(:any)/(:num)’] = “gifts/users_gifts_public/$1/$2”;

I just need urls like ../tom/123 work and return me user and ID to verify it in my code.

Basically the problem is that $1 is not recognised as variable (I guess $2 neither) so the routing doesnt work as instead "tom" url receives "$1"

The annoying thing is that so many people have come across this problem and there is no solution posted on the forum.
#4

[eluser]BrianDHall[/eluser]
[quote author="Takapaka" date="1256692160"]Actually to beter ilustrate please have a look at this line>

$route[’(:any)/(:num)’] = “gifts/users_gifts_public/$1/$2”;

I just need urls like ../tom/123 work and return me user and ID to verify it in my code.

Basically the problem is that $1 is not recognised as variable (I guess $2 neither) so the routing doesnt work as instead "tom" url receives "$1"

The annoying thing is that so many people have come across this problem and there is no solution posted on the forum.[/quote]

OK, you just need some custom regex then, don't worry about the built-in :any sort of helpers. Nothing like good old regex.

What exactly would some real strings look like? I'm sure we could help you build a regex that would do what you want.
#5

[eluser]Takapaka[/eluser]
Actually nothing more complex than routing url like:

www.site.com/gifts/users_gifts_public/john/654

(where john would be user name, and 654 his id)

to

www.site.com/john/654
#6

[eluser]BrianDHall[/eluser]
[quote author="Takapaka" date="1256694517"]Actually nothing more complex than routing url like:

www.site.com/gifts/users_gifts_public/john/654

(where john would be user name, and 654 his id)

to

www.site.com/john/654[/quote]

You're in luck, I had a strange urge to play with regex Big Grin

All tested and guaranteed working or your money back Wink

You have two options:

Code:
$route['([a-z_A-Z]+/[0-9]+)'] = "gifts/users_gifts_public/$1";

Before Route: john/654/123/123
After: gifts/users_gifts_public/john/654

Notice the other stuff after gets knocked off, so if you add anything else after you will find 404s or other unexpected behavior.

So what I recommend instead is:

Code:
$route['([a-z_A-Z]+/[0-9]+.+)'] = "pensacola_coupons/test/$1";

Before Route: john/654/123/123
After: gifts/users_gifts_public/john/654/123/123

Quod erat demonstrandum.

Resources for regex in the future: http://www.regular-expressions.info

And any editor that supports regex for search/replace functions. I keep EditPlus around for this, but any that supports regex will do. Much easier and faster to test in an editor than inside PHP script.

Enjoy!
#7

[eluser]BrianDHall[/eluser]
For fun, lets break down why that works with the regex: ([a-z_A-Z]+/[0-9]+.+)

First, the parens captures what matches inside so we can use in variables, such as $1, $2, etc.

Next: [a-z_A-Z]+

Inside the brackets we say "match a-z (lower-case), underscore, or A-Z (uppercase)", and then with plus as say "at least 1 or more instances of any of these, please". So in a string like "test/testing", the regex alone would match 'test' or 'testing' just as well.

But we don't stop there. We ask for a '/' all by itself, then we ask for: [0-9]+

That means "any number 0-9, please" with the + meaning "at least 1 or more instances, thanks".

Finally: .+

The dot means "OK, go ahead and capture Everything after, I don't care what it is, whatever", and the plus makes it "greedy", meaning "everything you have, please! nothing, something, one thing, a million things, I'll take it!" - because the dot loves everything and everyone.

If this route matches something before some other route matches something (it goes in order of definition, top of file to bottom), everything inside the parens becomes available to you as $1 as it is what was caught by the regex.
#8

[eluser]Takapaka[/eluser]
Thanks a lot BrianDHal,I really do appreciate, but even with Regex I get this annoying> The URI you submitted has disallowed characters: $1
:-S arrgh
#9

[eluser]BrianDHall[/eluser]
Hm, then there is something going wrong elsewhere, it shouldn't do that.

First, ensure your rewrite rule is using double-quotes. If you use single quotes it will Not work.

Code:
// this should work
$route['([a-z_A-Z]+/[0-9]+.+)'] = "pensacola_coupons/test/$1";

// this may NOT work
$route['([a-z_A-Z]+/[0-9]+.+)'] = 'pensacola_coupons/test/$1';

If that isn't working then something is really wonky. What routes do you have before - is this the first route defined in routes.php?

For now you can also go to config.php and $config['permitted_uri_chars'] add the $ sign, (I can't remember if you need '$' or "\$', so try both).

If you are still having this it isn't a route problem, as it works on my system.

Without a debugger I can't say why, but perhaps try installing a fresh version of CI somewhere else and trying it there. If that doesn't work something is definately odd - perhaps check different version of $config['uri_protocol'] settings to double-check.
#10

[eluser]BrianDHall[/eluser]
Hm, this is even odder - I don't have $ enabled in my permitted chars, yet a url like http://localhost/john/13$2$/$$rwer gets rerouted just fine using the rules I posted.

Curiouser and curiouser...




Theme © iAndrew 2016 - Forum software by © MyBB