Why is .htaccess mod rewrite rule not activating? - php

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]

Related

How to setup rule in .htacces to remove two sub directories

I have setup .htaccess to rewrite some rules in our system and they are all working fine.
Howevever, i am having trouble with the following rule. Can anyone help with this?
I have the following URL
test.com/admin/page/files/TEMPFILES/file.pdf
I would like this to be redirected if the url contains the following two strings "/admin/page/" AND "TEMPFILES"
i would like this to redirect to the following
test.com/files/TEMPFILES/file.pdf
I have tried the following
RewriteCond %{QUERY_STRING} ^TEMPFILES
RewriteCond %{REQUEST_URI} ^admin/([a-z]+)(/.*) [NC]
RewriteRule ^(/.*)?$ $2 [NC,L,QSA]
Any help will be appreciated.
Following URL
test.com/admin/page/files/TEMPFILES/file.pdf
should redirect to
test.com/files/TEMPFILES/file.pdf
You can use this
RewriteEngine on
RewriteCond %{REQUEST_URI} /admin/page/files/TEMPFILES/(.+)\.pdf$
RewriteRule (.*) /files/TEMPFILES/%1.pdf [L,R=301]
This will redirect /admin/page/files/TEMPFILES/foobar.pdf to /files/TEMPFILES/foobar.pdf .

.htaccess rewrite get parameter inside the URL

I'm having troubles to rewrite a get parameter inside the URL.
I need to replace to 0 the value or delete at all next request "filter=all" from urls across entire site.
Example of entire requst:
mysite.com/?filter=all&search_text=&type=xx&pagination=10&search_page=10&cs_loc_max_input=300&cs_loc_incr_step=1&goe_location_enable=off&submit=
I've tried:
RewriteRule ^filter=0$ filter=all&%{QUERY_STRING} [L,NC]
OR
RewriteCond %{QUERY_STRING} ^filter=all$
RewriteRule ^filter=0$ ?filter=all&%{QUERY_STRING}[L,NC]
OR
RewriteCond %{QUERY_STRING} ^(.*[&?]|)filter=(all|all2)([&?].*|)$
RewriteRule ^(.*)$ $1?filter=0&%{QUERY_STRING} [R=301,NC,L]
And few ways more, but nothing works as expected... Please, need a help.
Thanks
You can use:
RewriteCond %{QUERY_STRING} ^(.*)filter=all(.*)$ [NC]
RewriteRule ^ %{REQUEST_URI}?%1filter=0%2 [R=301,L]
If you try to rewrite without redirect. Use [L] instead of [R=301,L].

basic URL Rewriting in php issue

I have url coming on my web page like:
www.abc.com/product_list.php?id=12&pId=1&gpId=0
I want it to show like:
www.abc.com/product_list.php/12/1/0
i know this is very basic question but i am new in php.
your help will be really appreciated.
I did experiment like this but its not working: (in my htaccess file by googling)
RewriteRule ^product_list.php /product_list.php/id=$1/pId=$2/gpId=$3 [NC]
My .htaccessfile:
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteCond %{HTTP_USER_AGENT} (google|yahoo|msn|aol|bing) [OR]
RewriteCond %{HTTP_REFERER} (google|yahoo|msn|aol|bing)
RewriteRule ^([^/]*)/$ hamper-anastassia.php?$1 [L]
RewriteRule index.html$ /index.php
RewriteRule about.html$ /about.php
RewriteRule products.html$ /products.php
RewriteRule partners.html$ /partners.php
RewriteRule career.html$ /career.php
RewriteRule contact.html$ /contact.php
RewriteRule products_(.*)_(.*).html$ products.php?id=$2 [L]
RewriteRule ^product_list/([0-9]+)/([0-9]+)/([0-9]+)/?$ /product_list.php?id=$1&pId=$2&gpId=$3 [NC]
You should remove the .php
A simple example to capture the first parameter.
RewriteRule ^products/([0-9]+)/?$ show_a_product.php?product_id=$1
More here
https://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/
Basically every pairing of brackets catches a variable, this is where the $1, $2, $3 comes from.
RewriteRule ^product_list.php/([0-9]+)/([0-9]+)/([0-9]+)/?$ /product_list.php?id=$1&pId=$2&gpId=$3 [NC]
As Geoffrey mentions you could go one step further and remove the need for .php but that's up to you, e.g:
RewriteRule ^product_list/([0-9]+)/([0-9]+)/([0-9]+)/?$ /product_list.php?id=$1&pId=$2&gpId=$3 [NC]
Meaning you could visit /product_list/12/1/0
Please remove/comment everything in your .htaccess file then type only these two statements
RewriteEngine on
RewriteRule ^products/([0-9]+)/([0-9]+)/([0-9]+)/?$ products.php?id=$1&pid=$2&gpid=$3
Your url should be like this:
/products/1/2/3
If your still getting and error check your mod_rewrite configurations

rewrite php to png with some pramaters on .htaccess

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]

.htaccess if statement?

I haven't worked with .htaccess too much. Looking to do something like this:
When user types in domain.com/path it is then pulled from domain.com/index.php/path/to/file
UNLESS
someones goes to domain.com/admin
How can an add a exception or if statement for a few words that i dont want to redirect?
Put a rule for the admin rewrite first and use [L] at the end to tell .htaccess this is the last rule it should follow. Then, put your other rules after it.
Example:
RewriteRule ^admin(/?)$ - [L]
RewriteRule ^(.*)$ /path/to/file.php?id=$1
Using the - after the match rule means it won't rewrite it, it'll just go to the path that was provided.
You need to add a RewriteCond rule to exclude stuff from the rewrite rule.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^admin
RewriteCond %{REQUEST_URI} !^index.php
RewriteRule ^(.*)$ /index.php/$1 [L]

Categories