.htaccess
RewriteRule ^classroom$ dashboard.php?section=classroom [NC]
url
http://localhost/elearning/classroom?keyword=all
php
echo $_GET['keyword'];
and the problem is why i cant get the value from the url?
can you guys help me to solve this one? Thanks .
When rewriting this URL, the original URL's query string will not be sent to the new URL.
Place your .htaccess inside the elearning directory.
Change
RewriteRule ^classroom$ dashboard.php?section=classroom [NC]
to
RewriteRule ^classroom/(\w+)/$ dashboard.php?section=classroom&keyword=$1
Access URL:
http://localhost/elearning/classroom/all/
[UPDATE]
The above idea would work, but there's a standard way of achieving this by adding the QSA (Query String Append) flag for your original rewrite rule.
RewriteRule ^classroom$ dashboard.php?section=classroom [NC,QSA]
that will satisfy your request URL
http://localhost/elearning/classroom?keyword=all
Related
I have my site url like this.
https://example.com/page/1/?orderby=low_to_high&s=demo+post&post_type=post&twdg_wsac=1
I want to replace some part of this url using htaccess so the final output should be like this
https://example.com/page/1/?orderby=low_to_high&s=demo+post&post_type=post&custom_posts=1
So I have made changes in the htaccess file like this
RewriteEngine on
RewriteRule ^&twdg_wsac$ &custom_posts
But its not working. Also as you can see in the url there is twdg_wsac=1. So the last "1" is a pagination for post so that would change dynamically as per posts count.
So can someone tell me how to do this?
Any help and suggestions would be really helpful. Thanks
Update
All the parameters in the url are dynamically generated I mean those are the filter parameters. So they cant be same except twdg_wsac
Try with below, we are doing rewrite on query string.
RewriteEngine On
RewriteCond %{QUERY_STRING} ^orderby=(.+)&s=(.+)&post_type=(.+)&twdg_wsac=([\d]+)$
RewriteRule ^ %{REQUEST_URI}?orderby=%1&s=%2&post_type=%3&custom_posts=%4
RewriteEngine On
RewriteCond %{QUERY_STRING} twdg_wsac=([\d]+)$
RewriteRule ^ %{REQUEST_URI}?orderby=low_to_high&s=demo+post&post_type=post&custom_posts=%1 [L]
I'm having trouble redirecting some urls as below, there are many urls with different cat breeds. Can anyone help with this issue.
Example url to redirect :
http://www.exampledomain.co.uk/cats/database.nsf/catsforsale!openform?Breed=Persian
I want it directing to the url below. My php script should then do some more complex redirect to make the url tidy :
http://www.exampledomain.co.uk/display_pets.php?pettype=Cats&petbreed=Persian
I've tried the rewrite below but it doesnt work, it just doesnt redirect at all, i think it may have something to do with the ? :
RewriteRule ^/cats/database.nsf/catsforsale!openform?Breed=(.*)$ display_pets.php?pettype=Cats&petbreed=$1 [L]
RewriteRule normally does not look at query strings.
You need to use the QSA flag with Rewrite. It combines the query strings and appends it to the target url.
You can try the following:
RewriteRule ^(.*)$ display_pets.php?url=$1 [L]
This will pass the entire source url to the url parameter of the target url. It will also append the query strings of the source url to the target url.
Another option is to match the query string inside RewriteCond.
RewriteCond %{QUERY_STRING} url=(.*)
RewriteRule ^/cats/database.nsf/catsforsale!openform$ display_pets.php?pettype=Cats&petbreed=%1 [L]
See following links:
RewriteRule Flags and
Manipulating the Query String
This is an image rotator that I'm trying to be able to manage completely through the url to avoid having to setup a user login system. With this system, the urls of the images to be added and removed from the list are passed through the url as a variable. When I type out the entire url: http://www.url.com/index.php?add=http://www.url2.com/images/image.png it works fine. When I try to do it with an htaccess file, http://www.url.com/add=http://www.url2.com/images/image.png, I get a 403.
Applicable .htaccess line:
RewriteRule ^add\=(.*)/? index.php?add=$1 [QSA]
This htaccess line works as long as I'm not trying to submit an entire url. Any ideas? If this isn't enough information just let me know.
-- Edit --
Added more information about the url that I'm trying to retreive
Try this rule:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{THE_REQUEST} /add=(\S+) [NC]
RewriteRule ^ /index.php?add=%1 [QSA,L]
Comment from Ultimater and the solution:
The reason is because it's not a valid URL to begin with. You can't have two colons in the path. You can have them in the query string though but not in the path. http://localhost/add=http://localhost/ is an invalid URL. You can, however put a ? in front so it accepts the colon. Or simply omit the scheme. – Ultimater
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 want to change url for example http://www.mysite.com/cgshop/admin/index.php?route=common/home will become http://www.mysite.com/cgshop/cp/index.php?route=common/home.
Please help me to figure out this. Thanks in advance.
This should get you what you want.
It tests to see if the URI begins with /cgshop/admin/ and then captures the rest so it can redirect with a 301 to the new url. The QSA means it will also carry over the query string (everything after the ?).
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/cgshop/admin/.*$
RewriteRule ^cgshop/admin/(.*)$ /cgshop/cp/$1 [R=301,L,QSA]
RewriteEngine On
RewriteRule ^cgshop/cp/.*$ cgshop/admin/$1
Try this.......