.htaccess rewriterule with a period at the end - .htaccess

I set this rule in my .htaccess
RewriteRule (.*)/feyundco/ /$1?fq[ps_brand]=Fey+%26+Co. [P,L,R=301]
but when I reach the page, for example, example.com/search/feyundco the redirection doesn't work.
Same rule for other brands works like a charm
RewriteRule (.*)/modular/ /$1?fq[ps_brand]=Modular [P,L,R=301]
Where is the problem? The . at the end, the %26 (&) or what?
Thanks

Related

Redirect URL changing QUERY string parameter ? to & with .htaccess

I am trying to change this url:
http://blabla.nl/download/?url=https://www.bla.com/see?v=345345&type=download
to this:
http://blabla.nl/download/?url=https://www.bla.com/see&v=345345&type=download
Using .htaccess
so the ? needs to change to an &.
at the moment i am not very succesfull fixing this.
You have to do it this way:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^(url=https://www\.youtube\.com/watch)\?(v=[A-Za-z0-9]+&type=downloa‌​d)
RewriteRule ^/?8/downloadff/?$ /8/downloadff/?%1&%2 [R=301,NC,L]
I assume that the number 345345 is always a number an will be different all the times but the rest keeps the same.
Put this as .htaccess file on http://example.nl/ or http://example.nl/download/
Try this:
RewriteEngine On
RewriteRule ^download/?url=https://www.bla.com/see&v=345345&type=download/?$ download/?url=https://www.bla.com/see?v=345345&type=download [NC,L]
I hope it works for you.

RewriteRule redirects to unexpected page

I am trying to change my url through .htaccess in the following way
Original URL: http://www.example.com/latest-news.php?id=2/topic=testing
Rewritten URL:http://www.example.com/2/testing
Rule for .htaccess
RewriteRule ^([^/]*)/([^/]*)$ /latest-news.php?id=$1&topic=$2 [L]
This is working fine but the other files which are existing in a folder are not opening. The url is opening as www.example.com/testing/foo.php but content of the page is of http://www.example.com/2/testing
Can you try with a similar rule like the one bellow?
RewriteRule ^([0-9]+)/([a-zA-Z])$ /latest-news.php?id=$1&topic=$2 [L]
Can't really test it on my server but you can adapt it to suit your needs
RewriteEngine On
RewriteRule ^([0-9]+)/([^/]*)$ /latest-news.php?id=$1&url=$2 [L]
Since second part consists characters and digits So I modify the answer of stoica. Thanks #stoica

Redirect PHP URL with parameters

I have a website with several URLs like these:
domain.com/aff_link.php?id=363
and I need to redirect all of them to a subfolder called "old"
like this:
domain.com/old/aff_link.php?id=363
those numbers at the end go from 2 up to 4 digits.
How can I do this in htaccess?
Currently I have this code
RewriteCond %{QUERY_STRING} (^|&)(id)=[^&]+ [NC]
RewriteRule ^(/.*)?$ http://domain.com/old? [R=301,L,NC]
but that redirects everthing to domain.com/old/
so as you can see I do not know what I am doing, please help.
Thank you in advance.
This should be pretty close ...
RewriteEngine On
RewriteRule (aff_link.php) old/$1 [L,QSA,R=301]
Watch out for leading slashes depending on whether this is in a VirtualHost or Directory or .htaccess block.

Adding trailing slash to URL using htaccess

I'm trying to re-write my URL using htaccess. Here is the code from my htaccess:
RewriteRule ^post/([^/.]+)?/([^/.]+)?$
post.php?pst=$1&view=$2%{QUERY_STRING}
Everything is working fine, except that this code doesn't add a trailing slash at the end of the re-written URL. How can I add that?
I don't think you can access %{QUERY_STRING} in a RewriteRule; only a RewriteCondition. I think you might need to do something like:
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^post/([^/.]+)?/([^/.]+)?$ post.php?pst=$1&view=$2%1/
See: http://wiki.apache.org/httpd/RewriteQueryString

.htaccess: how to only rewrite .php URL?

My rewriterule with a condition is working fine as below:
http://www.sitename.com/index.php?n=text redirects to
http://www.sitename.com/pages/text
and the page renders properly, however, there is a problem that with the redirected URL the arguments are also added to the URL. So actually in address bar it looks like-
http://www.sitename.com/pages/text?n=text
Could anyone help me on this? The htaccess code is given below.
RewriteCond %{QUERY_STRING} ^n=(.*)$
RewriteRule index.php http://www.sitename.com/pages/%1 [r=301,nc]
You probably want to catch "index.php.*". Otherwise mod_rewrite only replaces the "index.php" part of the URL "index.php?n=text" with the new URL.
Guss,
From what you suggested, i reconstructed it as follows:
RewriteCond %{QUERY_STRING} ^n=(.*)$
RewriteRule index.php.* http://www.sitename.com/pages/%1 [r=301,nc]
This doesnt seem to be working either. Can you please elaborate on what you have said?
thank you
aditya
don´t use the url in the rewrite rule, apache then sends a http 200 code and then the 301...
try sth. like this:
RewriteRule (index\.php)(?n=)(.*) /pages/$3 [r=301]

Resources