Forum Moderators: phranque

Message Too Old, No Replies

Remove Query Strings From Url With Subdirectories

query strings, remove, url, subdirectories

         

starams5

3:18 pm on Aug 30, 2014 (gmt 0)

10+ Year Member



This is my first post even though I've been visiting the site for some time now. So I want to start off by thanking the community for all the tips I've taken away from here in the past.

I've been trying to resolve a query string issue for months now. I've tried numerous rewrite rules in .htaccess, but no luck so far. Could someone please help me get past this. I'm trying to remove query strings from the links below.

http://www.example.com/application/css.php?request=application%2Fthemes%2Ftreehouse%2Ftheme.css&c=1121&pageStart=295491&pageEnd=551218

not2easy

6:27 pm on Aug 30, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Welcome to the Forums starams5. In dynamically generated URLs, you can often control these easier dealing with settings.

Is this an URL created by a CMS, a plugin or an application you are using? This URL does not appear to be the URL of a page, but part of a process.

starams5

8:32 pm on Aug 30, 2014 (gmt 0)

10+ Year Member



Hi not2easy,

Thanks for your time, much appreciated. GTmetrex is telling me I need to fix this, but you're right it doesn't appear to be a page. I've been working on this all morning, still no solution. I'm not very good with rewrites, so I'll just tell you what I've found so far.

The funny url's are being created by scaffolding, they're all css files, about 8 of them. I didn't see any reason to bother the forum with all of them. If I can get the first straightened out, I can handle the rest.

example file with no strings: theme_paginator_pagestart=283459_pageend=379288_morning.css

I wasn't sure if it was cool to post code so I uploaded my .htaccess, css.php, and scaffold.php files to MediaFire. Again, thanks for the assistance.

MediaFire .htaccess, css.php, scaffold.php

[edited by: not2easy at 12:36 am (utc) on Dec 12, 2020]
[edit reason] removed broken link [/edit]

not2easy

9:16 pm on Aug 30, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I don't think this is htaccess related problem, though it may turn out to be something that could be fixed there. I would try to find the problem, look for its source and fix it there. it looks like you may have issues with "scaffolding" handling the "/" character in URLs (sorry, scaffolding.php is not something I am familiar with).

This part of the URL shown:
application%2Fthemes%2Ftreehouse%2Ftheme
happens when a browser needs to add urlencoding to a request because the folder name has a character "/" that isn't accepted or isn't being understood in it. I don't think you have any folders named application%2Fthemes%2Ftreehouse%2Ftheme but you may have folders named application/themes/treehouse/theme and whatever scaffolding is, it does not handle that / syntax.

lucy24

9:39 pm on Aug 30, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I wasn't sure if it was cool to post code

Backward :) You are supposed to post code-- but only the relevant parts. Don't dump the entire page source or, in this case, your entire htaccess.

If the problem applies only to CSS, and you want to remove all query strings, then one possible pattern is

RewriteCond %{QUERY_STRING} .
RewriteRule ^(.+\.css) http://www.example.com/$1? [R=301,L]


The first line-- the Condition-- simply says "If a query string exists". The ? at the end of the target then says "remove the query string". You need the Condition to prevent an infinite loop if there was no query in the first place.

theme_paginator_pagestart=283459_pageend=379288_morning.css

Yikes. Is that the actual name of your actual CSS file that the pages actually use? With all those = signs? Honestly that looks more like a query string whose content has been spliced onto the URL somehow. Is this a CMS?

starams5

11:59 pm on Aug 30, 2014 (gmt 0)

10+ Year Member



Hi not2easy, Hi lucy24,

I've research this high and low. I found a few others complaining about the same string. I even tried disabling scaffolding on my test box ... it didn't go so well, lost all css.

@lucy24 I tried the code below (with my site of course), and GTmetrex is still telling me I need to fix the link (Remove query strings from static resources). I've tried other rewrite rules that made perfectly good sense as well, and they didn't work either.

RewriteCond %{QUERY_STRING} .
RewriteRule ^(.+\.css) http://www.example.com/$1? [R=301,L]

Here is what I'm going to do. I'll leave lucy24's rewrite rule in there for a day or so, and give the caches time to clear, site, cdn, etc. This has worked for others, maybe it will work for me. I'll report back. This site is the best.

Thanks guys for your help.

lucy24

8:19 am on Aug 31, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



GTmetrex is still telling me I need to fix the link

Oh now wait. Are we talking about the URLs of individual files, or are we talking about links included in HTML documents? All the htaccess rules in the world won't change HTML that already exists. If your CMS is wantonly attaching query strings to stylesheet links, you'll have to make it stop.

:: wandering off to find out who or what GTmetrex is ::