Jump to content

Conflicting Regex to Clean URLS


Lukeidiot

Recommended Posts

Hello,
 
I seem to having an issue figuring out the right mix of regex here.
 

---------------------------------------------first-------------------------------------------------------second-----------------------------------------------

url.rewrite-once = ( "^/sc5/([^.?]*)$" => "/sc5/index.php?go=$1", "^/sc5/view/(.*)" => "/sc5/view/index.php?i=$1" )
 
The first mod_rewrite makes my url clean by changing example.com/?go=test to example.com/test
 
The second mod_rewrite (IS SUPPOSED) to make the same thing happen, but in another directory.
 
 
So my question is: How do I rewrite the first regex to ignore folders or slashes? As I believe this is the root of the problem.

Link to comment
https://forums.phpfreaks.com/topic/285460-conflicting-regex-to-clean-urls/
Share on other sites

 

Where is the dolar sign in second example?

 

Try,

"^/?sc5/view/(.*)$" => "/sc5/view/index.php?i=$1"

 

I changed that but I dont think that is my problem.

 

Its that everything in /sc5/ folder is being included into index.php, even the dirs (sc5/view/)

No.

If you have a string for example:

/sc5/view/jazzman the service's engine should be redirect it to /sc5/view/index.php?i=jazzman.

That's all and pretty simple.

 

PS: Does a sc5 directory is a subdirectory of root one or is a subdir of another directory in the server?

Describe the server structure.

No.

If you have a string for example:

/sc5/view/jazzman the service's engine should be redirect it to /sc5/view/index.php?i=jazzman.

That's all and pretty simple.

 

PS: Does a sc5 directory is a subdirectory of root one or is a subdir of another directory in the server?

Describe the server structure.

 

/html/sc5 is the server directory (the main site is in /html/sc5 and the view is in /html/sc5/view)

 

Your method DOES work, the only problem is that the first regex (or second, order doesnt matter it seems with lighttpd) overrides your regex.

What kind of router are you using? Are you using controllers? I guess I don't see why the rewrite rules are a good choice for doing what you are doing.

 

Well that is half the problem -- I'm not very good with regex. My main goal is to rewrite example.com/index.php?go=test to example.com/test/, then rewrite example.com/view/index.php?i=100 to example.com/view/1

If you only have a couple of rewrites, you might try using mod_rewrite (and one of the thousands of tutorials found online). If you've never used one of the popular php frameworks, you might check one out, even if all you do is use it for routing. In fact, if all you need is a good routing solution, Slim is worth looking at.

If you only have a couple of rewrites, you might try using mod_rewrite (and one of the thousands of tutorials found online). If you've never used one of the popular php frameworks, you might check one out, even if all you do is use it for routing. In fact, if all you need is a good routing solution, Slim is worth looking at.

 

I am using lighttpd which does not support mod_rewrite, nor .htaccess. That is why I have to apply the regex directly to my server config file (lighttpd.conf).

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.