We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Question, Problem

Stripping PHP from URL is making Search not work

Currently I have an htaccess directive that I'm using that is stripping the .php from the end of all files on my website. I'm struggling to get my blog search to display properly and I believe this is the issue. Here is the blog search page which is not showing any entries even though it should. https://testingserver3.work/blog/search?q=air . I had the same issue with this htaccess directive getting a blog sitemap to work properly and Simon and I were able to get it figured out here is the post and we used an htaccess directive that made it work (http://forum.grabaperch.com/forum/06-26-2018-blog-sitemap). I tried to do somthing like this and it failed in htaccess.

RewriteRule ^blog/search\.php?.(.*)$ - [L]

I tried the above directive because the following code fixes the blog sitemap

RewriteRule ^blog/blogSitemap\.php$ - [L]

This same issue was created when I could not get forms to process properly because the PHP was stripped. I was informed I need to add an action code directly to the form code. Search is also a form so it is possible I need to add an action code directly to the search.html template. Any suggestions would be great as I'm stumped.

Matt Holovach

Matt Holovach 0 points

  • 1 year ago

Anyone know if there is either a Perch solution to a the search-form template or an htaccess solution?

Drew McLellan

Drew McLellan 2638 points
Perch Support

How is it failing? What happens?

The search doesn't happen but the search page loads. It appears like the search has a form like functionality to it. I noticed that when we stripped the PHP from URLs that forms would not work unless we added a directive to the form template something like action="thank-you".

Not sure if the search-form template requires something like this as well? If I take out the php stripping htaccess directive the search form works properly.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, you can set an action on the search form. Does the search term appear in your URL when the result page loads?

Yes the search term does appear in the stripped search. The stripped version of the search looks like this. https://cgplumbing.com/blog/search?q=Sink

But if I take out the PHP stripping htaccess directive the URL would look like this https://cgplumbing.com/blog/search.php?q=Sink

What should the action code include?

Drew McLellan

Drew McLellan 2638 points
Perch Support

That looks like it should work then. If you turn on debug, what does it output?

Here is the debug

Debug Message - Perch 3.1.1
[42] SELECT DISTINCT settingID, settingValue FROM perch3_settings WHERE userID=0
[nil] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch3_blog_index idx JOIN perch3_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch3_blog_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='postID' AND idx2.indexKey='_id' WHERE 1=1 AND ((idx.indexKey='postSlug' AND idx.indexValue='search')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID, idx2.indexValue, postID ) as tbl WHERE (postStatus='Published' AND postDateTime<='2018-08-03 11:07:00' ) GROUP BY itemID, sortval ORDER BY sortval ASC LIMIT 0, 10
[1] SELECT FOUND_ROWS() AS `count`
Using template: /templates/blog/meta_head.html
[1] SELECT * FROM perch3_blog_posts WHERE postStatus='Published' AND postDateTime<='2018-08-03 11:07:00' AND postSlug='search'
[nil] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch3_blog_index idx JOIN perch3_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch3_blog_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='postID' AND idx2.indexKey='_id' WHERE 1=1 AND ((idx.indexKey='postSlug' AND idx.indexValue='search')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID, idx2.indexValue, postID ) as tbl WHERE (postStatus='Published' AND postDateTime<='2018-08-03 11:07:00' ) GROUP BY itemID, sortval ORDER BY sortval ASC LIMIT 0, 10
[1] SELECT FOUND_ROWS() AS `count`
Using template: /templates/blog/post.html
Fetching from cache: perch_blog_post_categoriesdd8092fd3bf31c5d23f6f6da888cc5b0
Cache file not found: perch_blog_post_categoriesdd8092fd3bf31c5d23f6f6da888cc5b0
[nil] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch3_blog_index idx JOIN perch3_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch3_blog_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='postID' AND idx2.indexKey='_id' WHERE 1=1 AND ((idx.indexKey='postSlug' AND idx.indexValue='search')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID, idx2.indexValue, postID ) as tbl WHERE (postStatus='Published' AND postDateTime<='2018-08-03 11:07:00' ) GROUP BY itemID, sortval ORDER BY sortval ASC LIMIT 0, 10
[1] SELECT FOUND_ROWS() AS `count`
Using template: /templates/blog/post.html
[nil] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch3_blog_index idx JOIN perch3_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch3_blog_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='postID' AND idx2.indexKey='_id' WHERE 1=1 AND ((idx.indexKey='postSlug' AND idx.indexValue='search')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID, idx2.indexValue, postID ) as tbl WHERE (postStatus='Published' AND postDateTime<='2018-08-03 11:07:00' ) GROUP BY itemID, sortval ORDER BY sortval ASC LIMIT 0, 10
[1] SELECT FOUND_ROWS() AS `count`
Using template: /templates/blog/post.html
[1] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch3_blog_index idx JOIN perch3_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch3_blog_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='postID' AND idx2.indexKey='postDateTime' WHERE 1=1 AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID, idx2.indexValue, postID ) as tbl WHERE (postStatus='Published' AND postDateTime<='2018-08-03 11:07:00' ) GROUP BY itemID, sortval ORDER BY sortval DESC LIMIT 0, 1
[1] SELECT FOUND_ROWS() AS `count`
[1] Using template: /templates/blog/post_prev.html
[4] SELECT * FROM perch3_blog_sections ORDER BY sectionTitle ASC
[1] SELECT * FROM perch3_blogs ORDER BY blogTitle ASC
[1] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch3_blog_index idx JOIN perch3_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch3_blog_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='postID' AND idx2.indexKey='postDateTime' WHERE 1=1 AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID, idx2.indexValue, postID ) as tbl WHERE (postStatus='Published' AND postDateTime<='2018-08-03 11:07:00' ) GROUP BY itemID, sortval ORDER BY sortval ASC LIMIT 0, 1
[1] SELECT FOUND_ROWS() AS `count`
[1] Using template: /templates/blog/post_next.html
[1] SELECT * FROM perch3_blog_posts WHERE postID=0 AND postStatus='Published' AND postDateTime<='2018-08-03 11:07:00'
[0] Using template: /templates/blog/ping_form.html
[nil] SELECT * FROM perch3_blog_comments WHERE 1=1 AND postID=0 AND commentStatus='LIVE' ORDER BY FIELD(webmentionType, 'like', 'repost', 'comment', NULL) ASC, commentDateTime ASC
[0] Using template: /templates/blog/comment.html
[0] Using template: /templates/blog/comment_form.html
Using template: /templates/search/search-form.html

Array
(
    [type] => 8
    [message] => Undefined offset: 0
    [file] => /home/a305odix8des/public_html/_cms/templates/layouts/blogPreviousNext.php
    [line] => 14
)

Drew McLellan

Drew McLellan 2638 points
Perch Support

That appears to be looking for a blog post with a slug of search. Is that what you'd expect?

Might this be an issue with your rewrite rules?

No worries Drew. I just added in the following htaccess directive and the search works now. So the php is stripped from everything but the search function.

RewriteRule ^blog/search\.php$ - [L]