post parameters to htaccess sef link - linux

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]

Related

.htaccess redirect home.html to root but allow query strings

I want to 301 redirect home.html to the root to avoid duplicate content. I can do this like this:
RewriteRule ^/home.html$ / [NC,R=301]
However there is a legacy affiliate program that use home.html like this:
home.html?a=companyname
Is there a way to allow the affiliate links, but still 301 home.html?
The query string will be appended automatically. From the docs:
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.

URL Rewrite keep %20 in Query String

I am trying to make a rewrite rule to move all pdf's on my site to point to a specific page and then use a Query String as the pdf's current file path to do a look up in a dictionary to see if that url is in my dictionary if it is redirect them to the correct page. The catch is my dictionary of urls has %20 and when I pull the query string it turns the %20 in a space. Thanks for any and all help.
Can you rewrite it to keep the %20 in the query string?
Example URL: /example/example/Big%20Small%20Something%20Pad.pdf
My Rewrite:
RewriteRule ([^/]*)\.pdf$ /redirectPDF.aspx?pdf=$1.pdf [NE,QSA]
Current Query String Output: Big Small Something Pad.pdf
What I want it to look like is Big%20Small%20Someting%20Pad.pdf
Try removing the NE flag. According to ISAPI docs:
http://www.helicontech.com/isapi_rewrite/doc/RewriteRule.htm:
noescape|NE
Don't escape output. By default ISAPI_Rewrite will encode all non-ANSI >characters as %xx hex codes in output.
So it looks like you simply want to omit the NE so that it'll encode the output like it does by default.
RewriteRule ([^/]*)\.pdf$ /redirectPDF.aspx?pdf=$1.pdf [QSA]

How do i receive additional query parameters with htaccess

My url looks like this.
http://www.example.com/fb-ex1.php
http://www.example.com/fb-exg2.php
http://www.example.com/fb-exx3.php
Htaccess
RewriteRule ^fb-([a-zA-Z0-9-_]+)\.php$ fb.php?query1=$1 [L]
Now, When the user logs in, I guess i am not able to receive the code and state variable
How do i change the rewirte rule to receive additional query parameters?
Couple of mistakes:
hyphen should be at the start or at the end in a character class otherwise it needs to be escaped.
Not using QSA (query string append) flag. This flag ensures to preserve existing query parameters while adding new ones.
Your rule should be rewritten to:
RewriteRule ^fb-([\w-]+)\.php$ fb.php?query1=$1 [L,QSA,NC]

Htaccess parameter overwrite + allow additional params?

I have a rule in my .htaccess file to overwrite ugly parameter urls with clean paths.
Here is an example:
RewriteRule ^landing(/)?([0-9]+)?(/)?$ landing/index.php?intPage=$2
So when someone goes to /landing/3, it would load the index.php page passing intPage parameters as 3.
Very simple.
However, I'm using techniques to trace Google Analytics referals, so I need to tack parameters onto this URL:
For example:
/landing/3?kt_type=ad&kt_st1=adwords&kt_st2=prize_a_us.en
The problem is that, I don't know how to retrieve the parameters that are tacked onto the URL, since the URL has already been overwritten and now I can't retrieve kt_type, kt_st1 etc.
Any idea on how to make it possible so I can still tack parameters to already overwritten URLs?
Use QSA flag. Change your rule to this:
RewriteRule ^landing/?([0-9]+)?/?$ landing/index.php?intPage=$1 [L,NC,QSA]
From official docs:
QSA - Appends any query string from the original request URL to any
query string created in the rewrite target

Problems with sorting comments in a SEF url system

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.

Resources