I'm having issues keeping the parameters of the URL working after an .htaccess URL rewrite.
My .htaccess rewrite is as follows:
RewriteEngine on
RewriteRule ^([a-z]{2,2})/([a-zA-Z0-9_-]+)$ index.php?lang=$1&page=$2
Which means:
example.com/index.php?lang=en&page=product displays as example.com/en/product
For some reason, when I add a ?model=AB123&color=something at the end of my URLs I am not able to retrieve those parameters in PHP using $_GET['model'] and $_GET['color'] even though they are present in the displayed URL.
Why aren't the variables passed along?
You need to append with the [QSA] (query string append) tag. Try
RewriteEngine on
RewriteRule ^([a-z]{2,2})/([a-zA-Z0-9_-]+)$ index.php?lang=$1&page=$2 [QSA]
See http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
Related
The problem I'm facing with .htaccess is that I want to pass the first segment of URL as a $_GET parameter so that for example www.example.com/en/ reads as www.example.com?language=en and www.example.com/category/groceries/?language=en reads as www.example.com/en/category/groceries , i want this to be done for all php pages without writing a rule for every page
here is what i tried without success
RewriteEngine on
RewriteRule ^en$ ?language=en&%{QUERY_STRING} [NC,L,QSA]
RewriteRule ^ar$ ?language=ar&%{QUERY_STRING} [NC,L,QSA]
However this doesn't work as intended
You can use this single rule for all the URLs:
RewriteEngine on
RewriteRule ^([a-z]{2})(/.*)?$ $2?language=$1 [L,QSA]
If you want to support only en as language identifier then use:
RewriteRule ^(en)(/.*)?$ $2?language=$1 [L,QSA]
I have a url like below
http://filespecification.phpnet.us/index3.php
But i want to add an additional parameter to this url like below.
http://filespecification.phpnet.us/index3.php?email=
For this i am using .htaccess to redirect with additional parameter but it is not redirecting still show original url.
RewriteRule /index3.php$ index3.php?email=$1 [R]
But it is not working. How can i redirect with additional parameter?
Try this simple one. Hope this will be helpful. I have tested it.
1. QUERY_STRING does not contain email.
2. if request uri is index3.php redirect to /index3.php?email=somevalue
Flags:
R for redirection.
L last redirection.
QSA query string append
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(?!email)
RewriteRule index3.php$ /index3.php?email=somevalue [L,R,QSA]
You can check this .htaccess code here http://htaccess.mwl.be/
Your rule isn't working due to the leading slash. You need to remove it.
RewriteCond %{THE_REQUEST} !\?email= [NC]
RewriteRule index3.php$ /index3.php?email=mail [L,R]
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'm interested in rewriting a url which is already "friendly" in order to clean up what is already in the path.
At the moment, I have a URI which points to http://example.com/page/index/home, but ideally id like to have the remove page/index completely, and just have http://example.com/home.
Something like the following...
RewriteEngine On
RewriteRule ^page/index/home$ /home [L]
If you know the specific page you are matching
To achieve what you want, you can just do this:
RewriteEngine On
RewriteRule ^/home$ /index.php [QSA,L]
QSA stands for Query String Append. It will append the query string (your GET parameters) to the end of your URL automatically if there is one.
You can use this rule in .htaccess file:
RewriteEngine On
RewriteRule ^home$ page/index/home [NC]
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]