Absolute path in RewriteRule - .htaccess

My link which need to be rewrited :
http://www.example.com/uploads/lu/full/00bcde2d484f1dab979c19f14b2f38bfabf13496_152_152.jpg
My rule
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)_([0-9]+)_([0-9]+)\.(jpg|jpeg|png|gif)$ http://test.mywebsite.com/themes/publisher/vignettes/resize.php?src=$1.$4&h=$2&w=$3
Output url
http://test.mywebsite.com/themes/publisher/vignettes/resize.php?src=uploads/lu/full/00bcde2d484f1dab979c19f14b2f38bfabf13496.jpg&h=152&w=152
Expected url
http://test.mywebsite.com/themes/publisher/vignettes/resize.php?src=http://www.example.com/uploads/lu/full/00bcde2d484f1dab979c19f14b2f38bfabf13496.jpg&h=152&w=152
http://www.example.com is not on my output url and i don't understand why

You need to capture values from %{REQUEST_URI that always contains full path:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^(.*)/([^/]*?)_([0-9]+)_([0-9]+)\.(jpe?g|png|gif)$ [NC]
RewriteRule ^ http://test.mywebsite.com/themes/publisher/vignettes/resize.php?src=http://%{HTTP_HOST}%1/%2.%5&h=%3&w=%4 [L,NE,R=302]

Related

How to Rewrite URL in htaccess

I have URLs with two query parameters e.g. /skills/keywords/list.php?industry=retail&q=analyst and I'd like to redirect those URLs to /list-of-%2-skills-in-%1 .
I have tried the code below which looks at the query "industry" and "q" to build the destination URL: /list-of-%2-skills-in-%1
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^industry=(.*)&q=(.*)$ [NC]
RewriteRule ^skills/keywords/list\.php$ /list-of-%2-skills-in-%1? [L,R=301]
I'm expecting: /skills/keywords/list.php?industry=retail&q=analyst to redirect to /list-of-analyst-skills-in-retail which it does but I have a 404 content not found.
Can someone point me to the right direction please?
This is because the destination path /list-of-%2-skills-in-%1 doesn't exist on your server. You need to rewrite this path to the existent file /skills/keywords/list.php?industry=retail&q=analyst .
RewriteEngine On
RewriteBase /
#redirect /skills/keywords/list.php?industry=foo&q=bar
#to /list-of-bar-skills-in-foo
RewriteCond %{THE_REQUEST} /skills/keywords/list\.php\?industry=([^&]*)&q=([^\s]+) [NC]
RewriteRule ^skills/keywords/list\.php$ /list-of-%2-skills-in-%1? [L,R=301]
#rewrite new URL to the old one
RewriteRule ^list-of-([^-]+)-skills-in-([^-]+)/?$ /skills/keywords/list.php?industry=$1&q=$2 [NC,L]

Redirect from several dynamic URLs to a unique URL

My actual and "desired" URL is (and works fine):
www.example.com/flower
The file is
www.example.com/indexmodelo.php?carpeta=flower
But I have the old URL to the same target ruled by "IP" instead "carpeta"
www.example.com/indexmodelo.php?IP=202
And I need that when you put:
www.example.com/indexmodelo.php?carpeta=flower
OR
www.example.com/indexmodelo.php?IP=202
Go to:
www.example.com/flower
In my .htaccess fil I have:
RewriteEngine on
Options -MultiViews
RewriteCond %{THE_REQUEST} \s/indexmodelo\.php\?carpeta=([0-9a-zA-Z_\-&=]+)\s [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteRule ^([0-9a-zA-Z_\-&=]+)$ /indexmodelo.php?carpeta=$1 [L]
Thanks for your help folks!

.htaccess RewriteRule(s) not working

I am trying to learn how to use RewriteRule.
I have 2 'pages' (wordpress)-
domain.com/webinars/ (shows list of all webinars)
and
domain.com/webinar/ (shows specific webinar details)
I have trying to set the following conditions -
(1) domain.com/webinars/{Year}/{Month}/ will load /webinar/?year={Year}&month={Month}
(2) domain.com/webinar/ (with no /{Year}/{Month}) will load /webinars/
(3) domain.com/webinar/?year={Year}&month={Month} will redirect to /webinars/{Year}/{Month}/ and then apply condition #1
This is my attempted code
RewriteEngine On
RewriteRule ^/webinars/([0-9]+)/([A-Za-z0-9]+)/$ /webinar/?year=$1&month=$2 [NC]
RewriteRule ^/webinar/$ /webinars/
RewriteRule ^/webinar/year=(\d+)$month=([\w-]+)$ /webinars/%1/%2? [R=301,L]
Condition #1 results in a 404 page not found
Condition #2 shows /webinar/ and not /webinars/
Condition #3 stays on domain.com/webinar/?year={Year}&month={Month} and does not redirect
What am I doing wrong? Only other code in my htaccess file is the default wordpress block.
Try the following :
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^webinars/([^/]+)/([^/]+) /webinar/?year=$1&month=$2 [NC]
The rest could be done the same way .
Try with below rules,
RewriteCond %{REQUEST_URI} ^/webinar$
RewriteCond %{QUERY_STRING} ^year=([^/]+)&month=([^/]+)
RewriteRule ^ http://example.com/webinars/%1/%2/? [R=302]
RewriteCond %{REQUEST_URI} ^/webinars/([^/]+)/([^/]+)/$
RewriteRule ^ webinar/?year=%1&month=%2 [L,END]
RewriteCond %{REQUEST_URI} ^/webinar/$
RewriteRule ^ webinars/ [L]
You can use this
RewriteEngine on
# if /webinar/ is requested skip the rules and serve /webinar/ directory
RewriteRule ^webinar/?$ - [L]
#redirect /webinar/?year={year}&month={month}
#To /webinar/year/month
RewriteCond %{THE_REQUEST} /webinar/\?year=([^\s&]+)&month=([^\s&]+) [NC]
RewriteRule ^.+$ /webinar/%1/%2? [L,R]
# rewrite new url to the old one
RewriteRule ^webinar/([^/]+)/([^/]+)/?$ /webinar/?year=$1&month=$2 [L,NC]

Put a parameter after url suffix

Using htaccess or any other way how can I pass a parameter to end of url suffix
EX: I need all the .html to be html?v=1
I tried the following
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.html$ $1.html?v=1 [R]
But Its not working
Check first that the query string does not already exist:
RewriteEngine On
RewriteCond %{QUERY_STRING} !v=1
RewriteRule ^(.*)\.html$ $1.html?v=1 [R,L]

URL Masking with htaccess 1

so this is my url:
http://www.mysite.com/mypage.php?PropertyBuyRent=rent&Developer=&Resort=&City=&State=&Country=&Price=
I want to write the following htaccess:
if PropertyBuyRent=rent and Resort value is not empty then url should be like:
http://www.mysite.com/mypage.php/TimeshareForRent/Marriott's+Grande+Ocean+Resort (whatever value comes from the url for Resort)
You can use this rule:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(testing/mypage\.php)\?PropertyBuyRent=rent&Developer=&Resort=([^&]+)&City=&State=&Country=&Price= [NC]
RewriteRule ^ /%1/TimeshareForRent/%2? [R=301,L,NE]
RewriteRule ^(testing/mypage.php)/TimeshareForRent/([^/]+)/?$ /$1?PropertyBuyRent=rent&Developer=&Resort=$2&City=&State=&Country=&Price= [L,NC,QSA]

Resources