Lighttpd and Pretty URLs.

Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions
Author Message
StillBlue
DD-WRT User


Joined: 11 Apr 2009
Posts: 257
Location: UK

PostPosted: Wed Apr 12, 2023 9:09    Post subject: Lighttpd and Pretty URLs. Reply with quote
I have been running Wordpress on DD-WRT successfully now for quite some time and I have been using lighttpd's mod_rewrite and the below code to achieve my pretty URLs.

Code:
url.rewrite = (
   "^/(.*)\.(.+)$" => "$0",
   "^/(.+)/?$" => "/index.php/$1"
)


However an issue I have is that the above acts for the whole folder served up by lighttpd, whereas ideally it would only be used on the wordpress site (eg I would like it to work for https://domain.com/wordpress and not the whole of https://domain.com)

I have tried to combat my issue by using:

Code:
$HTTP["host"] =~ "(www.)?domain.com/wordpress" {
   url.rewrite = (
      "^/(.*)\.(.+)$" => "$0",
      "^/(.+)/?$" => "/wordpress/index.php/$1"
   )
}


But for some reason whenever I add $HTTP["host"] to the code, it freezes up lighttpd.

I would be very grateful for guidance from anyone who can help with this.

Thanks
Sponsor
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1855
Location: Hung Hom, Hong Kong

PostPosted: Wed Apr 12, 2023 11:16    Post subject: Re: Lighttpd and Pretty URLs. Reply with quote
StillBlue wrote:
I have tried to combat my issue by using:

Code:
$HTTP["host"] =~ "(www.)?domain.com/wordpress" {
   url.rewrite = (
      "^/(.*)\.(.+)$" => "$0",
      "^/(.+)/?$" => "/wordpress/index.php/$1"
   )
}


But for some reason whenever I add $HTTP["host"] to the code, it freezes up lighttpd.

Looked like a LightTPD issue, mostly mod_rewrite?

I google "lighttpd mod_rewrite pretty url freeze" and "lighttpd mod_rewrite url freeze", found following replies:

Clean URLs (Permalinks) for WordPress on Lighttpd – Guy Rutenberg
https://www.guyrutenberg.com/2008/05/24/clean-urls-permalinks-for-wordpress-on-lighttpd/

Friendly URLs on Lighttpd - Using Friendly URLs | MODX Documentation
https://docs.modx.com/3.x/en/getting-started/friendly-urls/lighttpd

_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
StillBlue
DD-WRT User


Joined: 11 Apr 2009
Posts: 257
Location: UK

PostPosted: Wed Apr 12, 2023 14:29    Post subject: Reply with quote
Thank you. I have got myself on the right track now. I was using the $HOST incorrectly.

By using:

Code:

$HTTP["url"] =~ "^/wordpress/" {
   url.rewrite = (
      "^/(.*)\.(.+)$" => "$0",
      "^/(.+)/?$" => "/wordpress/index.php/$1"
   )
}


instead, the rewrite only applies to that folder. It does still seem to grind to a stop though, which I can't quite work out. I will have a few more goes at rewriting my variables.

I also need to work out how to get it to exclude some of the directories within /wordpress/ for instance something along the lines of

Code:
"^/(wp-admin|wp-includes|wp-content)/(.*)" => "$0",


But currently it seems to be ignoring that rule when I add it.
gstrauss
DD-WRT Novice


Joined: 16 Apr 2023
Posts: 2

PostPosted: Sun Apr 16, 2023 1:16    Post subject: Reply with quote
To match the domain:
Code:
$HTTP["host"] =~ "^(www.)?domain.com$" { ... }

To match the URL:
Code:
$HTTP["url"] =~ "^/wordpress/" { ... }


Check the version of lighttpd that you are using and consider upgrading if the lighttp version is ancient.

Your regular expressions in url.rewrite are suspect.

"^/(wp-admin|wp-includes|wp-content)/(.*)" => "$0", is ignored for you because you have the url.rewrite inside the condition $HTTP["host"] =~ "/wordpress", and your regex does not match a string starting with /wordpress

What are you trying to rewrite? It would appear that you want to leave alone anything that contains a literal '.' followed by anything, and rewrite the rest. Based only on what you have posted above, try this:
Code:
$HTTP["url"] =~ "^/wordpress" {
   url.rewrite = (
      "^/wordpress/(?:wp-admin|wp-includes|wp-content)/" => "", # => "" no rewrite for these paths
      "\.." => "",                                              # => "" no rewrite for these paths
      "" => "/wordpress/index.php${url.path}${qsa}"             # rewrite everything else
   )
}
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum