开发者

Using GET Query Strings with Expressionengine and Structure

开发者 https://www.devze.com 2023-03-16 10:07 出处:网络
I am trying to set up pagination on one of my EE Structure pages and the GET query string results in a 404 error. I think it has something to do with my .htaccess file but I cant figure it out. Here i

I am trying to set up pagination on one of my EE Structure pages and the GET query string results in a 404 error. I think it has something to do with my .htaccess file but I cant figure it out. Here is my .htaccess file, I'm using the exclude method for removing the index.php from the URL,

RewriteCond $1 !^(images|system|themes|modules|scripts|uploads|css|favicon\.ico|robots\.txt|index\.php|sitemap\.php|sitemap\.xml) [NC]
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]

So if I add some simple query like,

/accoun开发者_StackOverflow中文版t/?page=2

I get a 404 error...

Thanks for any help you guys can offer!


Yes, it's trying to find a template named "?page=2" and doesn't so it throws the 404 error.

Try using the index.php filename in the URL: /account/index.php?page=2.

Or, what I do is make the URL variables segments and use {segment_#} to parse them. So, /account/page2/ and then use {segment_2} in your template to get that variable.


Where are your GET query strings being generated from? Your method of removing index.php from the URL will not have any effect on what the generated {pagination_links} will be.

ExpressionEngine's paginations links simply add a /P5, /P10 or /P15 URL segment variable to the end of the current page's URL:

For example, given the following code:

{exp:channel:entries channel="site" dynamic="off" limit="5" paginate="bottom"}
    <p><a href="{title_permalink=structure/template}">{title}</a></p>

    {paginate}
        <p>Page {current_page} of {total_pages} pages {pagination_links}</p>
    {/paginate}
{/exp:channel:entries}

The HTML output by ExpressionEngine for pagination links will be:

<p>
    Page 1 of 3 pages <strong>1</strong>
    <a href="/structure/template/P5">2</a>
    <a href="/structure/template/P10">3</a>
    <a href="/structure/template/P5">&gt;</a>
</p>

You'll notice the pagination links don't use any GET or POST query string parameters and instead use a URL segment variable of P5, P10, P15, and so on (where P# is a multiple of the limit parameter and the current index of the paginated result set).


I was able to figure this out, not the most elegant option because it needs to be done for every page that you require query strings for...

RewriteCond %{QUERY_STRING} ^page
RewriteCond %{REQUEST_URI} ^/account/$ [NC]
RewriteRule (.*) /index.php?/account/index/&%{QUERY_STRING} [L]

So this means you can use,

/account/?page=2

And then grab the GET query normally using PHP.

Thanks for your contributions guys.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号