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]
Related
I'm trying to redirect a url but I can't seem to make it work for some reason. I'm trying to redirect my.domain.com/rss/abc/ to my.domain.com/rss/abc/?type=555
I've put this in my .htaccess
RewriteEngine On
# Redirects rss
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/rss/abc/?$ /rss/abc/?type=555 [R=301,L]
Any pointers ? This is on a old TYPO3 site. Anyway it could hijack the request before doing the redirect ?
I can only recommend to use some kind of online htaccess rewrite rule checker, for example https://htaccess.madewithlove.com/ (not the only one, and no real preferance or recommendation about others).
Your rewrite rule is wrong, it should be:
RewriteEngine On
# Redirects rss
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^rss/abc/?$ /rss/abc/?type=555 [R=301,L]
I have read about htaccess redirect and rewrite on stackoverflow and on other sites and learned how to redirect simple pages and directories, but there are about 30 links remaining that I haven't been able to redirect. The reason appears to be because they contain "?" in the link's URL. I've tried the solutions posted but I haven't been able to make enough sense of them to succeed.
These work:
Redirect /Corpfleet.php htp://www.marketyourcar.cm/wraps.php
Redirect /drivers.php htp://www.marketyourcar.cm/drivers.php
Redirect /galleries.php htp://www.marketyourcar.cm/galleries.php
These do NOT work:
Redirect /ad.php?View=FAQ htp://www.marketyourcar.cm/advertiser-faqs.php
Redirect /ad.php?View=gallery htp://www.marketyourcar.cm/galleries.php
Redirect /ad.php?View=Materials htp://www.marketyourcar.cm/products-services.php
Yes, I know that the URL above is htp and .cm - I had to break it in order to make this post with my low reputation level.
If anyone can help with this I'd appreciate it.
Thanks
If you want to redirect from like:
site.com/index.php?blabla=1&id=32
to
site.com/contact.html
then use:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} blabla=1&id=32
RewriteRule ^(.*)$ http://www.site.com/contact.html? [R=301,L]
</IfModule>
Redirect can't handle that. RewriteRule can. This should work.
RewriteEngine on
RewriteRule ^/ad\.php\?View\=FAQ$ http://www.marketyourcar.cm/advertiser-faqs.php [R=301,L]
RewriteRule ^/ad\.php\?View\=gallery$ http://www.marketyourcar.cm/galleries.php [R=301,L]
RewriteRule ^/ad\.php\?View\=Materials$ http://www.marketyourcar.cm/products-services.php [R=301,L]
Or try this:
RewriteEngine on
RewriteRule ^/ad.php?View=FAQ$ http://www.marketyourcar.cm/advertiser-faqs.php [R=301,L]
RewriteRule ^/ad.php?View=gallery$ http://www.marketyourcar.cm/galleries.php [R=301,L]
RewriteRule ^/ad.php?View=Materials$ http://www.marketyourcar.cm/products-services.php [R=301,L]
This might work:
Example:
RewriteEngine On
RewriteRule ^/ad.php?View=FAQ$ http://www.marketyourcar.cm/advertiser-faqs.php? [R=301,L]
Add a trailing ? to the substitution URL to remove the incoming query.
How to rewrite
/?custom_ref=
with
/?ref=
using htaccess rewrite???
RewriteEngine On
RewriteCond %{QUERY_STRING} custom_ref=(.*)
RewriteRule (.*) /?ref=%1 [R=301,L]
Can you please tell me the directory/file that you using this query on so I make sure this code will only work with it.
For many reasons, I need to rewrite my Base URL to a page, which is a hub.
i.e. http://data.mydomain.com always directs the user to http://data.mydomain.com/my-page
What's the best way to do this?
Use this
RewriteCond %{REQUEST_URI} !^/my-page
RewriteRule ^(.*)$ /my-page/$1 [L,R=301]
Did you try anything?
/?$ /my-page
Add this in you htaccess :
RewriteEngin on
RewriteCond %{HTTP_HOST} ^data.mydomain.com$
RewriteRule ^/?$ /my-page [L,R=301]
I have a dynamic query string that I need to pass via an .htaccess redirect. For example:
I need to redirect this URL: http://mysite.com/page1?action=signup&var2=dynamicVar
To this: http://mysite.com?action=signup&var2=dynamicVar
I know this is pretty simple, but I'm really not sure what type of rule/syntax would work for this.
Any help is greatly appreciated!
If you already have .htaccess then simply add this line:
RewriteRule ^page1/?$ page2 [L,R,QSA,NC]
Update: Based on your comments:
RewriteCond %{QUERY_STRING} (^|&)action=signup(&|$) [NC]
RewriteRule ^page1/?$ / [L,R,QSA,NC]
RewriteRule ^page1(.*)$ /page2$1 [L,R=301]
Input
http://mysite.com/page1?action=signup&var2=dynamicVar
this is the rewrite rule
RewriteRule ^page1?(.*)$ /?$1 [L,R=301]
redirect to
http://mysite.com/?action=signup&var2=dynamicVar
this will redirect all request o page1 with get parameters to http://mysite.com
Use %{REQUEST_URI}
fi.:
RewriteCond %{HTTP_HOST} ^website\.(.+)$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
rewrites anything that starts with "website" to "www.website..." including the querystring (by use of %{REQUEST_URI})