Problems with sorting comments in a SEF url system - .htaccess

I use Commentics for my website and having problem with my SEF urls. I couldn't find a solution in the related forum.
I have a rewrite rule like this :
RewriteRule ^([a-zA-Z0-9_-]+)$ /kurum.php?sef=$1
so my urls like http://fxrehber.com/kurum.php?sef=xtb
turns into this:
http://fxrehber.com/xtb
When I try to sort comments, that does not work
My url look like this :
http://fxrehber.com/xtb?cmtx_sort=5&sef=xtb#cmtx_comments
Is there way to solve this with an extra rewrite rule, or am I in the wrong direction?
Thank you

At last I found the simple solution for that: I just added "[QSA]" at the end of the rule as below:
RewriteRule ^([a-zA-Z0-9_-]+)$ /kurum.php?sef=$1 [QSA]
Source : http://httpd.apache.org/docs/current/mod/mod_rewrite.html
Modifying the Query String
By default, the query string is passed through unchanged. You can, however, create URLs in the substitution string containing a query string part. Simply use a question mark inside the substitution string to indicate that the following text should be re-injected into the query string. When you want to erase an existing query string, end the substitution string with just a question mark. To combine new and old query strings, use the [QSA] flag.

Related

post parameters to htaccess sef link

I have url for ex:
http://www.demo.com/a/abcd
And I use this htaccess to post this url's values
RewriteRule ^a/(.*)$ /details.php?sef=$1 [L,NC]
But I need to get new parameters posted the url
For ex:
http://www.demo.com/a/abcd?id=123&qu=11
So how can I get the id and qu variables values via this url without do any changes in URL?
From Apache's docs on mod-rewrite:
Modifying the Query String
By default, the query string is passed through unchanged. You can,
however, create URLs in the substitution string containing a query
string part. Simply use a question mark inside the substitution string
to indicate that the following text should be re-injected into the
query string. When you want to erase an existing query string, end the
substitution string with just a question mark. To combine new and old
query strings, use the [QSA] flag.
Since, you are writing the query string in a rewrite, use the QSA flag:
RewriteRule ^a/(.*)$ /details.php?sef=$1 [NC,QSA,L]

.htaccess, virtual directories, and semi-complex URLs

I'm basically just trying to have a master syntax for predictable URLs. Simple URL is no problem
RewriteEngine on
# RewriteRule ^friendlyUrl/content/?$ /index.php?app=main&module=content
Which to my understanding looks for the url structure and allows 1 or 0 trailing "/"'s
But some parts of the website have a /urlPrefix/ to access, eg. mysite.com/membersArea/
and /membersArea/ will be apart of every query there. I'm having trouble accomodating for trailing ?s and &s in URLs like these.
RewriteRule ^secureUrl/\?(.*)$ /index.php?app=admin&$1
This is my attempt to handle everything from mysite.com/secureUrl/ to mysite.com/secureUrl/?var1=foo&var2=bar and after many server errors and a search, I find myself here.
This is the most complex line I have and between you and me, I couldn't tell you exactly what's happening other than it looks for /friendlyUrl/10DIGITKEY/(possible task)/?possiblevars=foo&var2=bar
RewriteRule ^friendlyUrl/([a-zA-Z0-9]{10})/?([a-z]*)/?\??(.*)$ /index.php?app=main&module=web&id=$1&$2&$3
Htaccess has always been my weakest subject, and as a webmaster I pay the price constantly, any help would be appreciated.
Need to input the same request to the PHP file (plus ANY query with or without ? or &) whether its just /friendlyUrl/ or /friendyUrl/?var=1, /friendlyUrl/&var=1, /friendlyUrl/var=1
You're looking to keep the query string of your request URI to remain as is, or to be included in the rewritten URL after the rewrite process is done.
For this purpose, you use the QSA flag in your RewriteRule directive. So, to rewrite /friendlyUrl/10DIGITKEY/(possible task)/?possiblevars=foo&var2=bar, you'd have:
RewriteRule ^friendlyUrl/([a-z\d]{10})/([^/]*)/?$ /index.php?app=main&module=web&id=$1&task=$2 [QSA]
Notice the QSA flag at the end. Also, keep in mind that I'm passing the second match (the possible task of your URL) as another variable (named task). This variable will be empty if nothing was found.
QSA|qsappend
When the replacement URI contains a query string, the default behavior
of RewriteRule is to discard the existing query string, and replace it
with the newly generated one. Using the [QSA] flag causes the
query strings to be combined.

Getting Query String item after htaccess redirect

I have a re-written URL that will look like one of the following:
http://www.example.com/anyfolder/some-more-here/
http://www.example.com/anyfolder/some-more-here/?ref=referralcode
Here is the rule I was playing with:
RewriteRule ^([a-z0-9-]+)/([a-z0-9-]+)/?$ /page.asp?folder=$1&url=$2&refcode=$3 [NC,L]
My question is that since (http://www.example.com/anyfolder/some-more-here/?ref=) is a rewritten URL that has an additional query string item on it after the rewrite is done, how do I get that "ref" item in my code? I can easily get "anyfolder" and "some-more-here" by doing a simple request, but I am confused on the "ref" value part. I think the QSA flag might be needed, just having trouble bringing it all together.
I am using Classic ASP on this site, but the solution probably applies to PHP as well.
Any help would be great. thank you in advance!
Dennis
ok as per your comment you do need QSA flag. Try your rule as:
RewriteRule ^([a-z0-9-]+)/([a-z0-9-]+)/?$ /page.asp?folder=$1&url=$2&refcode=$3 [NC,L,QSA]
This will preserve ?ref=... in the rewritten URI.
QSA (Query String Append) flag preserves existing query parameters while adding a new one.

Mod rewrite with query strings after .html

Im trying to perform a mod rewriting to my web site. And I used to do this rewriting for quite some time. Of course I am very much upto the task until I met new requirement to create a rewritten URL with query strings after .html
Example - http://kypseli/admin/catagory.html?parent_id=1
I have used this this regex.
RewriteRule ^([A-Za-z0-9-/_]+).([html])/?$ index.php?rt=$1&%{QUERY_STRING}
But the query string value (parent_id) not passing.
This is working with out the .html part for perfection.
http://kypseli/admin/catagory/?parent_id=1
But I want it with .html part, as I have found lots and lots of same technique usage every where in WWW. here is one example
http://www.espncricinfo.com/ci/content/video_audio/559158.html?genre=46
Can someone please help.
If you want to get all query string elements from the first query to be appended on your rewritten query you need to add the [QSA] flag to the rewriteRule, or [qsappend] if you prefer long and descriptive tags.
RewriteRule ^([A-Za-z0-9-/_]+)/?$ index.php?rt=$1 [qsappend]
Now I do not understand fully what you mean about '.html', but I hope this will be enough.
EDIT
your problem is maybe the dot, it should be escaped \. and it should be in the optionnal part if it is optionall so :
RewriteRule ^([A-Za-z0-9-/_]+)/?$ index.php?rt=$1 [qsappend]
RewriteRule ^([A-Za-z0-9-/_]+)\.html?$ index.php?rt=$1 [qsappend]
Or if you want only one rule, this should work (untested)
RewriteRule ^([A-Za-z0-9-/_]+)([\.html|/])?$ index.php?rt=$1 [qsappend]
And it's unsure you really need the ? in your rewriteRule, you may want to apply it even without query strings.

simple explanation about .htaccess

I using it and use RewriteEngine
and i saw recently some text in the right side of RewriteEngine
like that
[L,QSA]
what this mean
and [L]
can eny one give me full list of them and usage for each one
They're documented at the mod_rewrite docs page:
'last|L' (last rule)
Stop the rewriting process here and don't apply any more rewrite rules. This corresponds to the Perl last command or the break command in C. Use this flag to prevent the currently rewritten URL from being rewritten further by following rules. Remember, however, that if the RewriteRule generates an internal redirect (which frequently occurs when rewriting in a per-directory context), this will reinject the request and will cause processing to be repeated starting from the first RewriteRule.
'qsappend|QSA' (query string append)
This flag forces the rewrite engine to append a query string part of the substitution string to the existing string, instead of replacing it. Use this when you want to add more data to the query string via a rewrite rule.
There is also a good cheat sheet here which I've found helpful.

Resources