I need to know how to configure the htaccess for when I access:
http://teste.com.br/route=feed/rest_api/count_products&key=123456
The action load most be:
http://teste.com.br/index.php?route=extension/feed/rest_api/count_products&key=123456
I need this to configuire an integration with another system.
Remembering that I need something generic that works for all methods within rest_api
I tried this but not work:
RewriteRule ^route=feed/? index.php?route=extension/feed/$1 [L]
You can use this rule as your top rule:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(route)=(feed/[^&]*&key=\d+)$ [NC]
RewriteRule ^(?:index\.php)?$ %{REQUEST_URI}?%1=extension/%2 [L,NC]
Related
It is possible to redirect in .htaccess
this url
http://test.com/uploads/image.jpg?w=200
to this
http://test.com/public/uploads/image/200.jpg
?
I need this to cache system in my rest API.
I'm not sure that is possible rewrite get variable in this way.
Cheers
Check this rule, maybe it help.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^uploads/image.jpg
RewriteCond %{QUERY_STRING} w=(.*)
RewriteRule ^(.*)$ /public/uploads/image/%1.jpg? [R=301,L]
How do I change example.com/1 to example.com/?id=1
I've tried googling but I can only find code for example.com/?id=1 to example.com/1
I used a generator and got this, but it didn't work
RewriteEngine On
RewriteRule ^\?get\=$ / [L]
Thanks,
Isaac
It kind of depends on which way you want to do the rewrite - ie, what does the user type see, and what does the server do.
If you want the user to see "http://example.com/1" and internally the server provides "http://example.com/?id=1", then the following should work:
RewriteRule ^([0-9]+)$ /?id=$1
However, if you want the user see "http://example.com/?id=1", and internally the server provides "http://example.com/1", then the following, as per Jon Lin's answer, should do it:
RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteRule ^$ /%1?
You can't match against the query string in a RewriteRule statement, you need to use a RewriteCond and the %{QUERY_STRING} variable:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteRule ^$ /%1? [L]
The ? is needed in the rule's target to remove the query string.
I have this dynamic link:
http://www.nortedigital.mx/article.php?id=36175&t=dobla_las_manos_el_snte__avala_reforma_educativa
and I need to convert in URL friendly like this:
http://www.nortedigital.mx/36174/se_enriquecio_elba_en_sexenios_del_pan.html
and i have this RewriteRule:
RewriteRule ^([^/]*)/([^/]*)\.html$ /article.php?id=$1&t=$2 [L]
but doesn't work. Please, anybody can help me?
You must capture the query string in a RewriteCond and use that in the RewriteRule
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=(\d+)&t=(.+)$
RewriteRule ^/?article\.php$ /%1/%2.html? [R,L]
This redirects the client to request i.e. /36174/se_enriquecio_elba_en_sexenios_del_pan.html. Now you must server the real page. For that, we add an additional rule, similar to the one you already have in your question
RewriteRule ^/?(.+?)/(.+?)\.html$ /article.php?id=$1&t=$2 [L]
But now, there's an endless redirect loop. We break this by using an environment variable. Here is the whole complete ruleset
RewriteEngine On
RewriteCond %{ENV:REDIRECT_SEO} ^$
RewriteCond %{QUERY_STRING} ^id=(\d+)&t=(.+)$
RewriteRule ^/?article\.php$ /%1/%2.html? [R,L]
RewriteRule ^/?(.+?)/(.+?)\.html$ /article.php?id=$1&t=$2 [L,E=SEO:1]
This rule does the redirect as above, as long as the environment variable is not set. And it serves the real page from article.php and sets the environment variable at the same time to prevent the loop.
You can use cookies for this purpose too. But that will break, if cookies are disabled in the client.
I need this logic to work:
I want rewrite this string for users to see
http://mysite.com/index.php?cl=mykeystring
to
http://mysite.com/otherkey/
http://mysite.com/index.php?myvar=test&cl=mykeystring&mysecondvar=morevalue
to
http://mysite.com/otherkey/myvar=test&mysecondvar=morevalue
But when http://mysite.com/otherkey/ is written, so load
http://mysite.com/index.php?cl=mykeystring, but no redirects will be done.
Is it possible? There are no possibility to change anything in codes, but only .htaccess
This logic is nearly realized by this code:
RewriteCond %{QUERY_STRING} ^(.*?)cl=mykeystring(.*?)$ [NC]
RewriteRule ^index.php$ /otherkey/%1%2? [R,L]
RewriteRule ^otherkey/(.*?)$ /index.php?cl=mykeystring&$1
but im getting some not needed amp symbols on first rewrite rule. any solutions?
I think you can do something like this:
RewriteCond %{QUERY_STRING} cl=mykeystring [NC]
RewriteRule ^index.php /otherkey/ [QSA]
Docs here: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
My server provider stopped give me possible way to create subdomains in control panel and they say I should solve it with htaccess.
So I have to do something like this. When user types http://asdf.example.com it should get the content of http://example.com/asdf (as the provider changed even the FTP's structure... how kind of them)
I don't find any tutorial for this. Thanks in advance.
More generic version of TerryE's answer. I haven't tested it though!!!
RewriteCond %{HTTP_HOST} !www.example.com
RewriteCond %{HTTP_HOST} (.*).example.com
RewriteCond %1/$0 !^([^/]+)/\1
RewriteRule ^.* %1/$0 [L]
You can do that with mod_rewrite and mod_proxy:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^asdf\.example\.com$
RewriteRule ^ http://example.com/asdf%{REQUEST_URI} [L,P]
You don't need mod proxy. Just do an internal redirect:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} =asdf.example.com
RewriteCond $0 !^asdf/
RewriteRule ^.* asdf/$0 [L]
The rule rewrite the request prefixing asdf/ but only if (1) the host is http:/asdf... and (2) the rewrite hasn't already taken place. You need (2) to prevent iterative loops. $0 is the match string in the rule.
Hope this helps.