Note that there are some explanatory texts on larger screens.

plurals
  1. PO.htaccess route with file check not working with querystring
    primarykey
    data
    text
    <p>I'm certainly no expert with .htaccess files, so bear with me..</p> <p>I have a nice simple rule:</p> <pre><code>RewriteCond %{DOCUMENT_ROOT}/landing-pages/$1.aspx -f RewriteRule ^/(.[^/]*)/?$ /landing-pages/$1.aspx [NC,L,QSA] </code></pre> <p>So if I go to a page: </p> <p><a href="http://myexampledomain.com/my-landing/page/" rel="nofollow">http://myexampledomain.com/my-landing/page/</a> </p> <p>It is rewritten correctly to: </p> <p><a href="http://myexampledomain.com/landing-pages/my-landing-page.aspx" rel="nofollow">http://myexampledomain.com/landing-pages/my-landing-page.aspx</a></p> <p>This works fine, until the original URL has a querystring on it: </p> <p><a href="http://myexampledomain.com/my-landing/page/?foo=bar" rel="nofollow">http://myexampledomain.com/my-landing/page/?foo=bar</a></p> <p>At this point, the rewrite condition isn't met (I assume the querystring is part of $1 ?) and so I get a page not found.</p> <p>I have tried changing my condition to:</p> <pre><code>RewriteCond /landing-pages/%{REQUEST_URI}.aspx -f </code></pre> <p>However, I suspect that %{REQUEST_URI} contains both leading and trailing slashes so that does not work either.</p> <p>Does anyone have any ideas on how I get the condition to ignore the querystring, but still append the querystring in the rule?</p> <p>Any help appreciated.</p> <p>p.s. I know routing is available in .net 3.5+ but currently that is not an option, we are already using .htaccess via Helicon's asapi_rewrite module.</p> <p>Thanks</p> <p>Edit:</p> <p>I have since added another condition and rule to try and narrow down where the problem is:</p> <pre><code>RewriteCond %{QUERY_STRING} foo=bar RewriteRule ^/(.*)/?$ /landing-pages/$1.aspx? [NC,L,QSA] </code></pre> <p>So now this is set to specifically Rewrite if the query string foo=bar exists. Using this I can see that the requested URL after the Rewrite is:</p> <p><a href="http://myexampledomain.com/landing-pages/my-landing-page/?foo=bar.aspx?foo=bar" rel="nofollow">http://myexampledomain.com/landing-pages/my-landing-page/?foo=bar.aspx?foo=bar</a></p> <p>It's certainly not how I expected it to behave..</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload