I have a project for modification, where I need to post a form with get, but I am unable to get the post value.
after checking I determine that .htaccess causing problem for this, please help me on this so I get the value without affecting the existing functionality of site.
this is .htaccess file
RewriteRule ^/?([a-zA-Z0-9_+-\s+]+)$ ?x=$1 [QSA,L]
RewriteRule ^/?([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)$ ?x=$1&y=$2
RewriteRule ^/?([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)$ ? x=$1&y=$2&z=$3
RewriteRule ^/?([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)$ ?x=$1&y=$2&z=$3&u=$4
RewriteRule ^/?([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)$ ?x=$1&y=$2&z=$3&u=$4&v=$5
RewriteRule ^/?([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)$ ?x=$1&y=$2&z=$3&u=$4&v=$5&w=$6
RewriteRule ^/?([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)$ ?x=$1&y=$2&z=$3&u=$4&v=$5&w=$6&a=$7
RewriteRule ^/?([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)/([a-zA-Z0-9_+-\s+]+)$ ?x=$1&y=$2&z=$3&u=$4&v=$5&w=$6&a=$7&b=$8
eg : http://www.exampledomain.com/result?term=sampleterm
in this the $_GET['x'] value is result, but I am unable to get term value
You actually need QSA flag (Query String Append), and its better to use L (Last) flag also.
RewriteRule ^/?([\w\s+-]+)/?$ ?x=$1 [QSA,L]
RewriteRule ^/?([\w\s+-]+)/([\w\s+-]+)/?$ ?x=$1&y=$2 [L,QSA]
RewriteRule ^/?([\w\s+-]+)/([\w\s+-]+)/([\w\s+-)/?$ ?x=$1&y=$2&z=$3 [L,QSA]
RewriteRule ^/?([\w\s+-]+)/([\w\s+-]+)/([\w\s+-]+)/([\w\s+-]+)/?$ ?x=$1&y=$2&z=$3&u=$4 [L,QSA]
# rest of the rules here...
QSA flag makes sure to append existing query string in the new query parameter you're adding through your rules.
Related
I have these rules that i want to make it work.
RewriteEngine on
RewriteRule ^/(view|show)/(ebook|lecture)/?$ page1.php?a=$1&b=$2 [L,QSA]
RewriteRule ^/(view|show)/(ebook|lecture)/([^/]+)/?$ page2.php?a=$1&b=$2&c=$3 [L,QSA]
RewriteRule ^/([^/]+)/-page-([0-9]+)?$ page3.php?a=$1&b=$2 [L,QSA]
My links are normally like this
www.domain.com/page1.php?a=view&b=ebook
www.domain.com/page2.php?a=view&b=ebook&c=title
www.domain.com/page3.php?a=title&b=6
and i want to turn them like the following look
www.domain.com/view/ebook //page1
www.domain.com/view/ebook/title //page2
www.domain.com/title/page-6 //page3
I've tried my rules but only the first one worked, But the page didn't load and the style was literally broken and not even a single image loaded or anything at all.
Try with:
RewriteEngine on
RewriteRule ^/?(view|show)/(ebook|lecture)/?$ page1.php?a=$1&b=$2 [L,QSA]
RewriteRule ^/?(view|show)/(ebook|lecture)/([^/]+)/?$ page2.php?a=$1&b=$2&c=$3 [L,QSA]
RewriteRule ^/?([^/]+)/page-([0-9]+)?$ page3.php?a=$1&b=$2 [L,QSA]
No leading slashes in left htaccess RewiteRule url (you can use RewriteRule ^(view...)
And you use only page- in your www.domain.com/title/page-6 //page3 link (not -page-)
I got the difficult when rewrite rules with multiple parameter,to modify a URL to SEO-friendly.
My URL:
http://domain/cat.php?alias=canon&sort=price&page=3
I want to have a rewrite rule so that the following:
http://domain/c/canon?sort=price&page=3
Heres my current rule:
RewriteEngine On
RewriteRule ^c/([a-z,0-9-]+)$ cat.php?alias=$1 [L]
RewriteRule ^c/([a-z,0-9-]+)?sort=([a-z]+)$ cat.php?alias=$1&sort=$2 [QSA]
RewriteRule ^c/([a-z,0-9-]+)?sort=([a-z]+)&page=([0-9]+)$ cat.php?alias=$1&sort=$2&page=$3 [QSA]
I try to get the params but it doesn't work. Anyone have any ideas on which rewrite rules to use?
Thank you!
--hatxi
RewriteRule ^c/([a-z,0-9-]+) cat.php?alias=$1 [L,QSA]
Should be enough. The QSA flag will take care of passing the sort and page parameters.
Your rules don't work because of the [L] flag on the first one, it just discards the rest because it always matches first.
I have a single get data (affid) that i want to retrieve using .htaccess but i don't know how to do it. Can you help me out?
Here is an example of links:
mysite.com/searchmembers?affid=1001
mysite.com/profle/123?affid=1002
mysite.com/videos/567?affid=1003
Another thing that might give a problem is these links already have been rewritten on .htaccess
RewriteRule ^searchmembers? index.php?task=searchMembers
RewriteRule ^profile/(.*)? index.php?task=viewProfile&id=$1
RewriteRule ^videos? index.php?task=videos&id=$1
i just want to retrieve the affid and add it to the links like this:
RewriteRule ^searchmembers... index.php?task=searchMembers&affid=(data retrieved)
RewriteRule ^profile/(.*)... index.php?task=viewProfile&id=$1&affid=(data retrieved)
RewriteRule ^videos? index.php... task=videos&id=$1&affid=(data retrieved)
i know i could add it on htaccess for each of these links but if there is an easier way to do this then it would be a great help. thank you for any response that i will receive!
Add this to your .htaccess in your web root / directory
RewriteEngine on
RewriteBase /
RewriteRule ^searchmembers$ index.php?task=searchMembers [QSA,NC,L]
RewriteRule ^profile/(.*)$ index.php?task=viewProfile&id=$1 [QSA,NC,L]
RewriteRule ^videos/(.*)$ index.php?task=videos&id=$1 [QSA,NC,L]
If you just need to append a new query parameter (like task here), any existing query parameters can be appended automatically using the [QSA] (Query String Append) flag. I've also corrected the regex used in your RewriteRules. The use of ? is incorrect.
I have following rewrite rule/condition in my htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^id([0-9]+)/?$ /profile.php?user_id=$1 [L]
The result is "example.com/id1"
Now the problem I have, I need to put a $_GET parameter sometimes to the URL, but actually they get ignored, example:
example.com/id1?section=video
example.com/id1?section=photo
example.com/id1?section=audio
Also not working:
example.com/id1§ion=video
Is there a chance to accomplish this task by extending the htaccess rule? Remember that the URL not always have the $_GET parameter added.
Best regards!
Try using the QSA flag
RewriteRule ^id([0-9]+)/?$ /profile.php?user_id=$1 [L,NC,QSA]
If I am mod_rewriting a URL from:
http://www.mysite.com/blog/this-is-my-title/1/
to
http://www.mysite.com/blog.php?title=this-is-my-title&id=1
...is it possible then to arbitrarily attach a get value on to the URL later, or does the mod_rewrite throw it off?
MY REWRITE RULE:
RewriteRule ^blog/([A-Za-z]+)/(0-9]+)/? blog?title=$1&id=$2 [L]
EXAMPLE:
can i go
http://www.mysite.com/blog/this-is-my-title/1/?first=Johnnie&last=Wiggles
which would essentially mean
http://www.mysite.com/blog.php?title=this-is-my-title&id=1&first=Johnnie&last=Wiggles
I would think that should work, but for some reason it's not for me at the moment.
You can add QSA to the RewriteRule flags:
RewriteRule page_([0-9]+)\.html page.php?id=$1 [QSA]
Will redirect page_1.html?a=2 to page.php?id=1&a=2
However, be careful because requesting page_1.html?id=2 will redirect to page.php?id=1&id=2, and (in PHP), $_GET['id'] will be 2.
It's possible to append it, with the QSA (query string append) flag.
RewriteEngine on
RewriteRule {from-url} {to-url} [L,NC,QSA]