Jump to content
Old threads will finally start getting archived ×

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

  On 1/17/2014 at 11:28 PM, kicken said:

Why not just swap the order of them so the second regex is tested first? Order all your rewrites from most-specific to least specific.

 

Good idea, but I just tried this way and it doesn't seem to make a difference.

  On 1/17/2014 at 11:52 PM, jazzman1 said:

 

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/)

Edited by Lukeidiot

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.

Edited by jazzman1
  On 1/18/2014 at 12:19 AM, jazzman1 said:

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.

  On 1/18/2014 at 2:30 AM, sKunKbad said:

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.

  On 1/18/2014 at 3:16 AM, sKunKbad said:

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).

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.