rewrite php to png with some pramaters on .htaccess - php

I want rewrite my link
/svlist/sv_image.php?ip=109.73.77.38&port=35115&game=cs2d
to
/svlist/cs2d/109.73.77.38:35115.png
I'm really new on that stuff.
RewriteRule ^(svlist)/([^.]*)\/([0-9]+):([^.]*)\.png$ $1/sv_image.php?ip=$3&port=$4&game=$2 [L,NC]
I tried this one and failed..

Try:
RewriteRule ^svlist/([^/]+)/([0-9.]+):([0-9]+)\.png$ /svlist/sv_image?ip=$2&port=$3&game=$1 [L,QSA]

If you want to rewrite /svlist/$var1/$var2:$var3.png into /svlist/sv_image.php?ip=$var2&port=$var3&game=$var1 you could check this:
# once per .htaccess file
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^svlist/([a-z0-9-_]+)/([0-9\.]*):([0-9]*).png /svlist/sv_image.php?ip=$2&port=$3&game=$1 [L,NC]
But if the URLs that you want to rewrite are /svlist/sv_image.php?ip=$var1&port=$var2&game=$var3 into /svlist/$var3/$var1:$var2.png then try to check these rewrite condition and rule:
RewriteCond %{QUERY_STRING} ip=([0-9\.]*)&port=([0-9]*)&game=([a-z0-9-_]+)
RewriteRule ^svlist/sv_image.php /svlist/%3/%1:%2.png [L,NC]

Related

Redirect URL as well as Change Query String Apache

I have two conditions:
http://localhost/restexample/api/con/2/
rewrites to
http://localhost/restexample/RestController.php?phone=single&id=2
and
http://localhost/restexample/api?number=12345
redirects/rewrites to
http://localhost/restexample/RestController.php?phone=all&no=12345
I am getting proper response in 1st case but not in second case.
My .htaccess file is:
# Turn rewrite engine on
Options +FollowSymlinks
RewriteEngine on
# map neat URL to internal URL
RewriteRule api/con/([0-9]+)/$ "RestController.php?phone=single&id=$1" [nc,qsa]
RewriteCond %{QUERY_STRING} number=(\d+)$
RewriteRule "^api" "RestController.php?phone=all&no=%1" [nc,qsa,R=301]
Somebody please help.
Output of second file:
Try these rules:
Options +FollowSymlinks
RewriteEngine on
# map neat URL to internal URL
RewriteRule ^api/con/([0-9]+)/?$ RestController.php?phone=single&id=$1 [NC,L,QSA]
RewriteCond %{QUERY_STRING} (?:^|&)number=(\d+)$
RewriteRule ^api/?$ RestController.php?phone=all&no=%1 [NC,L]

Why is .htaccess mod rewrite rule not activating?

I have the following two rules in my .htaccess file:
RewriteRule ^vacancies/test-feed/vacancies/status?user=(.*)$ vacancies/test-feed.php?mode=status&email=$1 [L,NC]
RewriteRule ^vacancies/test-feed/vacancies/(.*)$ vacancies/test-feed.php?mode=vacancy-info&job_id=$1 [L,NC]
I am accessing the url:
/vacancies/test-feed/vacancies/status?user=test#email.com
and I want that to activate the top rule, but it is actually activating the second and passing status?user=test#email.com as $1
Any help would be appreciated.
Try to replace the first rule with:
RewriteCond %{QUERY_STRING} user=([^&]+) [NC]
RewriteRule ^vacancies/test-feed/vacancies/status$ vacancies/test-feed.php?mode=status&email=%1 [L,NC]

htaccess rewrite index.php to .html

I have following rewriterules:
RewriteEngine On
RewriteRule ^([^\-]*)-(.*)-von-(.*)\.html$ $1index.php?filter=$2&marke=$3 [QSA]
RewriteRule ^([^\-]*)-von-(.*)\.html$ $1index.php?marke=$2 [QSA]
RewriteRule ^([^\-]*)-(.*)\.html$ $1index.php?filter=$2 [QSA]
RewriteRule ^(.*)\.html$ $1index.php
The first 3 rules are working, but the fourth, just rewrite index.php to .html is not. What is wrong here?
EDIT:
The URL is example.com/folder/subfolder/index.php
In the folder I got following htaccess:
RewriteEngine on
RewriteRule ^subfolder(.*) subfolder/$1
And the htaccess in subfolder is the one above
Now the URL for the first rule is example.com/folder/subfolder-value1-von-value2.html and works, for the second and third rule it's example.com/folder/subfolder-value1.html and example.com/folder/subfolder-von-value2.html
So with logic the fourth rule should also work just without the parameters but it's not working
Place this in /folder/.htaccess:
RewriteEngine on
RewriteRule ^subfolder\.html$ subfolder/index.php [L,NC]
RewriteRule ^subfolder(.+) subfolder/$1 [L,NC]
You shouldn't add $1 to the second part of the rule.it'll append the first matching group to the index.php file name. what you are currently getting is 'indexindex.php'
if you just want to rewrite index.html to index.php then you can place following line at the end of the file.
RewriteRule ^index.html$ index.php [L,NC]
also you might wanna remove $1 part from other lines as well.
Can you try this & see ?
RewriteEngine on
RewriteRule ^(.*)\.html $1\.php

.htaccess url rewriting

I need a rewrite rule to rewrite the following:
www.abc.com/page/xyz to www.abc.com/xyz
remove **"page"** from url
I think it's more like this:
RewriteBase /
RewriteRule ^(.*)$ page/$1 [L]
If I understand what you're trying to do.
Like so:
RewriteBase /
RewriteRule ^page(/.*)?$ $1 [L]
If you only want to redirect page/xyz then you can use:
RewriteEngine on
RewriteRule ^/page/xyz$ /xyz [L]
If you want to redirect anything within the page directory, then use:
RewriteEngine on
RewriteRule ^/page(/.*$)$ $1 [L]

apache rewrite static url to dynamic

I'm try to rewrite my url
http://www.domain.com/live/randomword
it should go rewrite to
http://www.domain.com/live/?cat=randomword
here are my tests:
RewriteRule ^live/(.*)$ /live/?cat=$1
RewriteRule ^live/(.*)$ live/?cat=$1
and all i have in the htaccess file is:
RewriteEngine on
You should try to add a RewriteBase / to your .htaccess and to suffix your rule with a [L] to say it's last rewrite rule ending with something like that:
RewriteEngine on
RewriteBase /
RewriteRule ^live/(.*)$ live/index.php?cat=$1 [L]
If this still doesn't work be sure to check that mod_rewrite is enabled
also you can do a [R,L] instead of [L] to see the redirection in the url and so have more info on what's going own.
hope this help
Have this code in your .htaccess file:
Options -MultiViews +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^live/(.*)$ /live/?cat=$1 [L,NC]
in rewrite rule the file name or extension in missing?
write rule like,
RewriteRule ^live/([a-zA-Z0-9_-]+)$ /viewcategory.php?cat=$1

Categories