{"id":16366411,"url":"https://github.com/centminmod/pretty-search-url","last_synced_at":"2025-04-14T16:32:48.285Z","repository":{"id":80279943,"uuid":"280242430","full_name":"centminmod/pretty-search-url","owner":"centminmod","description":"This plugin allows Wordpress `?s=wordpress+cache` query strings to be redirected to pretty url format `/search/wordpress+cache/`","archived":false,"fork":false,"pushed_at":"2021-07-14T10:12:51.000Z","size":48,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T05:24:08.903Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/centminmod.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-16T19:38:25.000Z","updated_at":"2023-01-03T16:44:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"703993c0-2ef4-4375-af72-536522ed78e1","html_url":"https://github.com/centminmod/pretty-search-url","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/centminmod%2Fpretty-search-url","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/centminmod%2Fpretty-search-url/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/centminmod%2Fpretty-search-url/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/centminmod%2Fpretty-search-url/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/centminmod","download_url":"https://codeload.github.com/centminmod/pretty-search-url/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248916876,"owners_count":21182882,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T02:46:22.232Z","updated_at":"2025-04-14T16:32:48.277Z","avatar_url":"https://github.com/centminmod.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pretty Search Url Wordpress Plugin\n\nThis plugin allows Wordpress `?s=wordpress+cache` query strings to be redirected to pretty url format `/search/wordpress+cache/` which is a necessary step to enable [Wordpress Cache Enabler plugin's](https://wordpress.org/plugins/cache-enabler/) advanced Nginx caching configuration with [Centmin Mod 123.09beta01 and higher's Wordpress auto installer setup](https://blog.centminmod.com/2019/07/15/122/how-to-install-wordpress-on-centmin-mod-lemp-stack-guide/) as outlined [here](https://community.centminmod.com/threads/caching-search-results-with-standard-centminmod-install.20027/#post-85037).\n\nCache Enabler plugin has 2 methods of doing caching:\n\n1. The default way for non-Centmin Mod LEMP stack plugin installs relies on Cache Enabler doing at PHP process level both cached file generation on requests and also doing the caching logic - determining if a request has an associated cached HTML page generated and whether to serve that cached HTML page or whether to bypass cache and grab the request from backend PHP/MySQL.\n\n\n2. Cache Enabler also allows you to configure advanced caching where the second part for caching logic is offloaded from PHP to the web server i.e. Centmin Mod Nginx. This is what [Centmin Mod 123.09beta01 and higher's LEMP stack Wordpress autoinstaller](https://community.centminmod.com/threads/differences-between-wordpress-regular-install-vs-centmin-sh-menu-option-22-install.15435/) configures for Cache Enabler out of the box - advanced guest full HTML page caching for Wordpress requests where PHP only generates the cached files but offloads the caching logic itself from PHP to Nginx. This allows for much faster caching performance as Nginx can serve cached files much better than serving the cached files through PHP process. That is why Centmin Mod's auto configured Cache Enabler caching performance is better than other folks caching results when they only install Cache Enabler plugin without configuring any advanced web server level caching logic offload.\n\nCache Enabler in this advanced caching mode will then do guest based full HTML page caching for Wordpress search requests from pretty url format `/search/wordpress+cache/` by saving the cached full HTML page to local disk cached file via PHP process for the first request. Then subequent requests will bypass PHP completely and move caching logic to Nginx level. So if a cached version of the request exists, Nginx server itself (not PHP) will determine if it will serve the cached file or if it detects a query string request i.e. `?s=wordpress+cache`, it will bypass Wordpress Pretty Search Url plugin's PHP logic for 302 redirect and let Nginx server itself do the 302 redirect to `/search/wordpress+cache/`. Allowing Nginx to do the 302 redirect instead of Pretty Search Url plugin's PHP based 302 redirect, results in up to 44x times faster performance!\n\n# Install\n\nYou can upload contents of this repository to `wp-content/plugins/pretty-search-url` directory you manually create and activate plugin from within Wordpress Admin.\n\nOr for [Centmin Mod LEMP stack Nginx users](https://centminmod.com), install from SSH command line - replacing domain variable `domain.com` with your domain name:\n\n```\ndomain=domain.com\ncd /home/nginx/domains/$domain/public/wp-content/plugins/\nmkdir -p pretty-search-url\nwget -O /home/nginx/domains/$domain/public/wp-content/plugins/pretty-search-url/pretty-search-url.php https://github.com/centminmod/pretty-search-url/raw/master/pretty-search-url.php\nwget -O /home/nginx/domains/$domain/public/wp-content/plugins/pretty-search-url/index.html https://github.com/centminmod/pretty-search-url/raw/master/index.html\nwget -O /home/nginx/domains/$domain/public/wp-content/plugins/pretty-search-url/readme.md https://github.com/centminmod/pretty-search-url/blob/master/readme.md\n#wget -O /home/nginx/domains/$domain/public/wp-content/plugins/pretty-search-url/LICENSE https://github.com/centminmod/pretty-search-url/raw/master/LICENSE\nchown -R nginx:nginx /home/nginx/domains/$domain/public/wp-content/plugins/pretty-search-url\nls -lah /home/nginx/domains/$domain/public/wp-content/plugins/pretty-search-url\ncd /home/nginx/domains/$domain/public\nwp plugin activate pretty-search-url\nwp plugin status pretty-search-url\n```\n\nActivate plugin\n\n```\ndomain=domain.com\ncd /home/nginx/domains/$domain/public\n\nwp plugin activate pretty-search-url  \nPlugin 'pretty-search-url' activated.\nSuccess: Activated 1 of 1 plugins.\n```\n\nCheck Status of plugin\n\n```\ndomain=domain.com\ncd /home/nginx/domains/$domain/public\n\nwp plugin status pretty-search-url\nPlugin pretty-search-url details:\n    Name: Pretty Search Url\n    Status: Active\n    Version: 0.1\n    Author: George Liu\n    Description: Redirect search to pretty /search/ urls\n```\n\nDeactivate plugin\n\n```\ndomain=domain.com\ncd /home/nginx/domains/$domain/public\n\nwp plugin deactivate pretty-search-url\nPlugin 'pretty-search-url' deactivated.\nSuccess: Deactivated 1 of 1 plugins.\n```\n\n# Example Enabling Wordpress Search Caching With Cache Enabler\n\nWordpress Cache Enabler plugin's advanced Nginx caching configuration with Centmin Mod 123.09beta01 and higher's Wordpress auto installer's Cache Enabler setup as outlined [here](https://community.centminmod.com/threads/caching-search-results-with-standard-centminmod-install.20027/#post-85037) after installing the Pretty Search Url plugin and making the following changes to KeyCDN's Cache Enabler's `cache_enabler.class.php` file to remove `is_search()` cache exclusion:\n\n```\ndiff -u cache_enabler.class.php-orig cache_enabler.class.php-removesearch \n--- cache_enabler.class.php-orig        2020-07-17 05:33:33.933006105 +0000\n+++ cache_enabler.class.php-removesearch        2020-07-17 05:34:17.572342714 +0000\n@@ -1407,7 +1407,7 @@\n         }\n \n         // conditional tags\n-        if ( self::_is_index() OR is_search() OR is_404() OR is_feed() OR is_trackback() OR is_robots() OR is_preview() OR post_password_required() ) {\n+        if ( self::_is_index() OR is_404() OR is_feed() OR is_trackback() OR is_robots() OR is_preview() OR post_password_required() ) {\n             return true;\n         }\n```\n\nI've posted an issue request on Cache Enabler's Github repo at https://github.com/keycdn/cache-enabler/issues/83 to add support for toggling Wordpress search cache exclusion at the WP admin dashboard level so that we don't need to do the above modifications. Fingers crossed :)\n\nThen in `/usr/local/nginx/conf/wpincludes/cache-enabler.domain.com/wpcacheenabler_cache-enabler.domain.com.conf` where domain of wordpress site = `cache-enabler.domain.com` is generated by centmin.sh menu option 22, reassigning $cache_uri with `/search/wordpres+cache` by changing parts of includes above the initial `set $cache_enabler_uri` to\n\nJuly 20, 2020 updated config so Nginx takes over from Wordpress redirects so PHP-FPM request is totally bypassed for query string `?s=` requests and specific `/search/` location match so that you can do more specific things in future i.e. rate limit within `/search/` if needed\n\nIn `/usr/local/nginx/conf/wpincludes/cache-enabler.domain.com/wpcacheenabler_cache-enabler.domain.com.conf`\n\nchange from\n\n```\n    # default html file\n    set $cache_enabler_uri '${custom_subdir}/wp-content/cache/cache-enabler/${http_host}${cache_uri}index.html';\n\n    # webp html file\n    if ($http_accept ~* \"image/webp\") {\n        set $cache_enabler_uri_webp '${custom_subdir}/wp-content/cache/cache-enabler/${http_host}${cache_uri}index-webp.html';\n    }\n```\n\nto\n\n```\n    if ($args ~* s=(.*)) {\n      set $cache_uri $request_uri;\n      set $check_surl $cache_uri;\n      set $cache_uri /search/$1/;\n      set $cache_uri_search /search/$1/;\n      set $cache_enabler_uri_search '${custom_subdir}/wp-content/cache/cache-enabler/${http_host}${cache_uri_search}index.html';\n    }\n    location ~ /search/(.*) {\n      add_header Search 1;\n      set $cache_uri $request_uri;\n      set $check_surl $cache_uri;\n      set $cache_uri_search $request_uri;\n      set $cache_enabler_uri_search '${custom_subdir}/wp-content/cache/cache-enabler/${http_host}${check_surl}index.html';\n      try_files $cache_enabler_uri_search $cache_enabler_uri_webp $cache_enabler_uri $uri $uri/ $custom_subdir/index.php?$args;\n    }\n    add_header Check-Uri \"$check_surl\";\n    add_header Set-Uri \"$cache_uri\";\n\n    # default html file\n    set $cache_enabler_uri '${custom_subdir}/wp-content/cache/cache-enabler/${http_host}${cache_uri}index.html';\n\n    # webp html file\n    if ($http_accept ~* \"image/webp\") {\n        set $cache_enabler_uri_webp '${custom_subdir}/wp-content/cache/cache-enabler/${http_host}${cache_uri}index-webp.html';\n    }\n\n    if (-f $document_root$cache_enabler_uri_search) {\n      set $search_exists $cache_enabler_uri_search;\n      return 302 https://$host$cache_uri_search;\n    }\n    if (!-f $document_root$cache_enabler_uri_search) {\n      set $search_exists $cache_enabler_uri_search;\n    }\n    #add_header Check-File \"$search_exists\";\n```\nSo now returned header via `Set-Uri` is = `$cache_uri`\n\n```\ncurl -IL http://cache-enabler.domain.com/?s=wordpress+cache\nHTTP/1.1 302 Moved Temporarily\nDate: Thu, 23 Jul 2020 07:14:11 GMT\nContent-Type: text/html\nContent-Length: 138\nConnection: keep-alive\nLocation: http://cache-enabler.domain.com/search/wordpress+cache/\nServer: nginx centminmod\nX-Powered-By: centminmod\nX-Xss-Protection: 1; mode=block\nX-Content-Type-Options: nosniff\nCheck-Uri: /?s=wordpress+cache\nSet-Uri: /search/wordpress+cache/\n\nHTTP/1.1 200 OK\nDate: Thu, 23 Jul 2020 07:14:11 GMT\nContent-Type: text/html; charset=utf-8\nContent-Length: 25301\nLast-Modified: Thu, 23 Jul 2020 07:10:12 GMT\nConnection: keep-alive\nVary: Accept-Encoding\nETag: \"5f1937d4-62d5\"\nServer: nginx centminmod\nX-Powered-By: centminmod\nSearch: 1\nAccept-Ranges: bytes\n\n```\ndirect cached url access\n```\ncurl -I http://cache-enabler.domain.com/search/wordpress+cache/\nHTTP/1.1 200 OK\nDate: Thu, 23 Jul 2020 07:16:17 GMT\nContent-Type: text/html; charset=utf-8\nContent-Length: 25301\nLast-Modified: Thu, 23 Jul 2020 07:10:12 GMT\nConnection: keep-alive\nVary: Accept-Encoding\nETag: \"5f1937d4-62d5\"\nServer: nginx centminmod\nX-Powered-By: centminmod\nSearch: 1\nAccept-Ranges: bytes\n```\n\n### wrk-cmm with wordpress search cached\n\nBefore July 20, 2020 load test with my forked wrk\n```\nwrk-cmm -t4 -c50 -d20s --latency --breakout http://cache-enabler.domain.com/search/worldpress+cache/\nRunning 20s test @ http://cache-enabler.domain.com/search/worldpress+cache/\n  4 threads and 50 connections\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\n    Latency     1.01ms    4.16ms  99.65ms   97.01%\n    Connect   159.21us   71.17us 288.00us   58.33%\n    TTFB        1.00ms    4.16ms  99.64ms   97.01%\n    TTLB       10.21us   32.01us  11.02ms   99.97%\n    Req/Sec    23.94k     9.82k   45.89k    64.12%\n  Latency Distribution\n     50%  415.00us\n     75%  603.00us\n     90%    1.19ms\n     99%   10.78ms\n  1907359 requests in 20.04s, 35.79GB read\nRequests/sec:  95189.83\nTransfer/sec:      1.79GB\n```\nJuly 20, 2020 updated load test with my forked wrk\n```\nwrk-cmm -t4 -c50 -d20s --latency --breakout http://cache-enabler.domain.com/search/wordpress+cache/\nRunning 20s test @ http://cache-enabler.domain.com/search/wordpress+cache/\n  4 threads and 50 connections\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\n    Latency     1.20ms    6.12ms 124.69ms   97.87%\n    Connect   179.00us   89.20us 362.00us   62.50%\n    TTFB        1.19ms    6.12ms 124.68ms   97.87%\n    TTLB       13.37us   59.32us  16.59ms   99.95%\n    Req/Sec    26.75k     8.31k   49.59k    65.29%\n  Latency Distribution\n     50%  304.00us\n     75%  576.00us\n     90%    1.38ms\n     95%    3.66ms\n     99%   11.13ms\n  2134184 requests in 20.11s, 50.92GB read\nRequests/sec: 106140.60\nTransfer/sec:      2.53GB\n```\nBefore July 20, 2020 direct query search cached\n```\nwrk-cmm -t4 -c50 -d20s --latency --breakout http://cache-enabler.domain.com/?s=wordpress+cache             \nRunning 20s test @ http://cache-enabler.domain.com/?s=wordpress+cache\n  4 threads and 50 connections\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\n    Latency   738.15us    2.44ms 108.60ms   95.81%\n    Connect   144.73us   69.16us 280.00us   60.42%\n    TTFB      724.86us    2.44ms 108.58ms   95.81%\n    TTLB       13.46us   58.63us  14.02ms   99.96%\n    Req/Sec    26.26k     6.27k   39.64k    70.00%\n  Latency Distribution\n     50%  351.00us\n     75%  546.00us\n     90%    1.21ms\n     99%    7.54ms\n  2092164 requests in 20.03s, 50.16GB read\nRequests/sec: 104448.19\nTransfer/sec:      2.50GB\n```\nJuly 20, 2020 updated direct query search cached which totally bypasses PHP-FPM if cached file exists\n```\nwrk-cmm -t4 -c50 -d20s --latency --breakout http://cache-enabler.domain.com/?s=wordpress+cache\nRunning 20s test @ http://cache-enabler.domain.com/?s=wordpress+cache\n  4 threads and 50 connections\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\n    Latency     0.92ms    2.17ms  50.59ms   90.15%\n    Connect     1.06ms  807.10us   2.76ms   58.27%\n    TTFB        0.91ms    2.17ms  50.59ms   90.15%\n    TTLB        2.17us   39.52us  10.77ms   99.98%\n    Req/Sec    51.04k    14.08k   72.57k    64.88%\n  Latency Distribution\n     50%  147.00us\n     75%  321.00us\n     90%    3.02ms\n     95%    5.94ms\n     99%    9.84ms\n  4065047 requests in 20.04s, 2.01GB read\nRequests/sec: 202841.81\nTransfer/sec:    102.72MB\n```\n\n### Checking If Wordpress Search Results Are Cached\n\nExample of the cached request file saved on disk at `/home/nginx/domains/cache-enabler.domain.com/public/wp-content/cache/cache-enabler/cache-enabler.domain.com/search/wordpress+cache` for both `index.html` and pre-gzip compressed `index.html.gz`. Centmin Mod Nginx server out of box is configured to serve the pre-gzip compressed version if it detects it exists which can improve Nginx static file serving performance by up to \u003e80x times compared to serving via Nginx's on the fly gzip compression.\n\n```\nls -lh /home/nginx/domains/cache-enabler.domain.com/public/wp-content/cache/cache-enabler/cache-enabler.domain.com/search/wordpress+cache\ntotal 36K\n-rw-rw---- 1 nginx nginx  25K Jul 23 07:10 index.html\n-rw-rw---- 1 nginx nginx 6.9K Jul 23 07:10 index.html.gz\n```\n\nOn the Wordpress search result page at `http://cache-enabler.domain.com/search/wordpress+cache/`, the HTML source code footer will have a comment indicating it was cached and pre-gzip compressed by Cache Enabler like\n\n```php\n!-- Cache Enabler by KeyCDN @ 23.07.2020 07:10:12 (html) --\u003e\n```\n\n### wrk-cmm with wordpress search non-cached\n\ncompared to default without wordpress search cache\n```\ncurl -IL http://cache-enabler.domain.com/?s=wordpress+cache                                                                                \nHTTP/1.1 200 OK\nDate: Thu, 16 Jul 2020 15:46:04 GMT\nContent-Type: text/html; charset=UTF-8\nConnection: keep-alive\nVary: Accept-Encoding\nLink: \u003chttp://cache-enabler.domain.com/wp-json/\u003e; rel=\"https://api.w.org/\"\nServer: nginx centminmod\nX-Powered-By: centminmod\nX-Xss-Protection: 1; mode=block\nX-Content-Type-Options: nosniff\nCheck-Uri: /?s=wordpress+cache\nSet-Uri: /?s=wordpress+cache\n```\nBefore July 20, 2020 non-cached search at 332 requests/sec\n```\nwrk-cmm -t4 -c50 -d20s --latency --breakout http://cache-enabler.domain.com/?s=wordpress+cache            \nRunning 20s test @ http://cache-enabler.domain.com/?s=wordpress+cache\n  4 threads and 50 connections\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\n    Latency   143.66ms   16.60ms 238.90ms   68.44%\n    Connect   165.79us   83.37us 334.00us   56.25%\n    TTFB      143.60ms   16.60ms 238.79ms   68.47%\n    TTLB       63.16us   25.84us   1.19ms   85.77%\n    Req/Sec    83.38     14.48   121.00     68.62%\n  Latency Distribution\n     50%  144.40ms\n     75%  154.74ms\n     90%  163.80ms\n     99%  185.14ms\n  6663 requests in 20.02s, 181.04MB read\nRequests/sec:    332.85\nTransfer/sec:      9.04MB\n```\nAfter July 20, 2020 non-cached search at 683.83 requests/sec\n\n```\nwrk-cmm -t4 -c50 -d20s --latency --breakout http://cache-enabler.domain.com/?s=wordpress+cache\nRunning 20s test @ http://cache-enabler.domain.com/?s=wordpress+cache\n  4 threads and 50 connections\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\n    Latency    70.02ms   11.92ms 164.77ms   71.72%\n    Connect   162.48us   73.21us 303.00us   58.33%\n    TTFB       70.01ms   11.92ms 164.76ms   71.71%\n    TTLB        4.24us    1.27us  54.00us   95.82%\n    Req/Sec   171.61     17.16   220.00     63.38%\n  Latency Distribution\n     50%   68.30ms\n     75%   76.17ms\n     90%   86.80ms\n     99%  103.26ms\n  13693 requests in 20.02s, 5.67MB read\nRequests/sec:    683.83\nTransfer/sec:    289.83KB\n```\n\n# Custom /search/ cache invalidation cronjob\n\nCentmin Mod 123.09beta01's centmin.sh menu option 22 wordpress auto installer with Cache Enabler caching selected will also generate an optional cronjob to invalidate and remove Cache Enabler cached files from cache and look similar to:\n\nRemove Cache Enabler's cached files every day at 11:16pm (every 24hrs).\n\n```\n16 23 * * * echo \"cache-enabler.domain.com cacheenabler cron\"; sleep 174s ; rm -rf /home/nginx/domains/cache-enabler.domain.com/public/wp-content/cache/cache-enabler/* \u003e /dev/null 2\u003e\u00261\n```\n\nWith above `/search/` caching modifications, you could setup a separate `/search/` cache invalidation cronjob which can have a shorter or longer interval than default Cache Enabler cache time.\n\nFor example delete `/search/` cached files every 5 minutes\n\n```\n*/5 * * * * echo \"cache-enabler.domain.com cacheenabler search cron\"; sleep 14s ; rm -rf /home/nginx/domains/cache-enabler.domain.com/public/wp-content/cache/cache-enabler/search/* \u003e /dev/null 2\u003e\u00261\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcentminmod%2Fpretty-search-url","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcentminmod%2Fpretty-search-url","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcentminmod%2Fpretty-search-url/lists"}