phranque

msg:4553702 | 12:55 am on Mar 12, 2013 (gmt 0) |
your regex has a start and end anchor which will fail the conditional test of QUERY_STRING.
|
g1smd

msg:4553712 | 2:06 am on Mar 12, 2013 (gmt 0) |
You'll need (^|&) and (&|$) here.
|
buildersweb

msg:4553832 | 9:33 am on Mar 12, 2013 (gmt 0) |
Thanks for your advise. I have tested the redirect like this RewriteCond %{QUERY_STRING} ^|&thepid=1777&|$ RewriteRule ^details2\.php$ [mydomain.com...] [R=301,L] But with no luck. Am i doing anything wrong ? Thanks
|
g1smd

msg:4553842 | 9:46 am on Mar 12, 2013 (gmt 0) |
Where did the brackets go? Use example.com in this forum so that the code is readable.
|
buildersweb

msg:4553853 | 10:00 am on Mar 12, 2013 (gmt 0) |
RewriteCond %{QUERY_STRING} ^|&thepid=1777&|$ RewriteRule ^details2\.php$ http://www.example.com/corner-sofas/302-sofa-corn.html? [R=301,L] IS the above wrong ?
|
buildersweb

msg:4553862 | 10:30 am on Mar 12, 2013 (gmt 0) |
I have also tested with brackets but it has not worked RewriteCond %{QUERY_STRING} (^|&)thepid=1777(&|$) RewriteRule ^details2\.php$ http://www.example.com/corner-sofas/302-sofa-corn.html? [R=301,L] [edited by: incrediBILL at 2:50 pm (utc) on Mar 12, 2013]
|
phranque

msg:4553863 | 10:30 am on Mar 12, 2013 (gmt 0) |
you'll need those grouping parentheses as provided in g1smd's example.
|
phranque

msg:4553864 | 10:32 am on Mar 12, 2013 (gmt 0) |
what response do you get?
|
buildersweb

msg:4553871 | 10:41 am on Mar 12, 2013 (gmt 0) |
no response the old link just stays as it is on the browser. www.example.com/details2.php?lang=1&wh=1&the1id=2&the2id=8&the3id=40&theid=40&open1=2&open2=8&open3=40&thepid=1777&page=1
|
phranque

msg:4553874 | 10:55 am on Mar 12, 2013 (gmt 0) |
do you have any other working mod_rewrite directives in that .htaccess file?
|
buildersweb

msg:4553883 | 11:33 am on Mar 12, 2013 (gmt 0) |
This is the .htaccess code . I have added the redirect outside the comments because presta renew this code. So at the end is the redirect i want to do.
RewriteOptions inherit
# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again # .htaccess automaticaly generated by PrestaShop e-commerce open-source solution # http://www.prestashop.com - http://www.prestashop.com/forums
<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_HOST} ^www.example.com$ RewriteRule . - [E=REWRITEBASE:/] RewriteRule ^api/?(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]
# Images RewriteCond %{HTTP_HOST} ^www.example.com$ RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L] RewriteCond %{HTTP_HOST} ^www.example.com$ RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L] RewriteCond %{HTTP_HOST} ^www.example.com$ RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.jpg [L] RewriteCond %{HTTP_HOST} ^www.example.com$ RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg [L] RewriteCond %{HTTP_HOST} ^www.example.com$ RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg [L] RewriteCond %{HTTP_HOST} ^www.example.com$ RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg [L] RewriteCond %{HTTP_HOST} ^www.example.com$ RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg [L] RewriteCond %{HTTP_HOST} ^www.example.com$ RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg [L] RewriteCond %{HTTP_HOST} ^www.example.com$ RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L] RewriteCond %{HTTP_HOST} ^www.example.com$ RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]
# Dispatcher RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteCond %{HTTP_HOST} ^www.example.com$ RewriteRule ^.*$ - [NC,L] RewriteCond %{HTTP_HOST} ^www.example.com$ RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L] </IfModule>
<IfModule mod_expires.c> ExpiresActive On ExpiresByType image/gif "access plus 1 month" ExpiresByType image/jpeg "access plus 1 month" ExpiresByType image/png "access plus 1 month" ExpiresByType text/css "access plus 1 week" ExpiresByType text/javascript "access plus 1 week" ExpiresByType application/javascript "access plus 1 week" ExpiresByType application/x-javascript "access plus 1 week" ExpiresByType image/x-icon "access plus 1 year" </IfModule>
FileETag INode MTime Size <IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE text/javascript AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/x-javascript </IfModule>
#If rewrite mod isn't enabled ErrorDocument 404 /index.php?controller=404
# ~~end~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
# i have also tested with [b]RewriteEngine on with no luck[/b] #RewriteEngine on [b]RewriteCond %{QUERY_STRING} (^|&)thepid=1777(&|$) RewriteRule ^details2\.php$ http://www.example.com/corner-sofas/302-sofa-corn.html? [R=301,L] [/b]
|
g1smd

msg:4553884 | 11:39 am on Mar 12, 2013 (gmt 0) |
Redirects should be listed before rewrites. Literal periods in RegEx patterns should be escaped.
|
buildersweb

msg:4553887 | 11:56 am on Mar 12, 2013 (gmt 0) |
I moved it to the start of htaccess. That worked THANKS!
|
buildersweb

msg:4555177 | 9:59 am on Mar 15, 2013 (gmt 0) |
I would like to ask for one more redirection I have 150 urls that are like this www.example.com/en/for-bar/985-bar-table.html I want to find a redirect rule in order to redirect them all at a url without the lang prefix "en/" www.example.com/for-bar/985-bar-table.html How can this be done ?
|
phranque

msg:4555187 | 10:09 am on Mar 15, 2013 (gmt 0) |
is everything in the /en/for-bar/ directory to be redirected to the /for-bar/ directory?
|
buildersweb

msg:4555203 | 10:38 am on Mar 15, 2013 (gmt 0) |
no everything is /en/ that need to be redirected to / actually to be deleted
|
phranque

msg:4555205 | 10:57 am on Mar 15, 2013 (gmt 0) |
in the RewriteRule pattern use a start anchor before the "en" and an end anchor after the "html". use parentheses to capture everything from the "/" to the "html" (inclusive) so you can use that as a back-reference in the substitution string. be sure to include the full canonical protocol and hostname in the substitution string and use the [R=301,L] flags for your redirect. put this rule before your general hostname canonicalization redirect. (they should be ordered most specific to most general.)
|
phranque

msg:4555206 | 10:58 am on Mar 15, 2013 (gmt 0) |
deleted or moved to the root?
|
lucy24

msg:4555213 | 11:05 am on Mar 15, 2013 (gmt 0) |
I think he means "deleted" as in "removed from the URL" so RewriteRule ^stuff/(more-assorted-stuff-here)$ http://www.example.com/$1 [R=301,L]
|
buildersweb

msg:4555222 | 11:20 am on Mar 15, 2013 (gmt 0) |
i have almost 150 urls like this www.example.com/en/for-bar/985-bar-table.html www.example.com/en/for-bar/1058-bar-table.html www.example.com/en/for-bar/2014-bar3-table1.html www.example.com/en/for-bar/254s-bar2-table3.html i want with one rule to make them all like this www.example.com/for-bar/985-bar-table.html www.example.com/for-bar/1058-bar-table.html www.example.com/for-bar/2014-bar3-table1.html www.example.com/for-bar/254s-bar2-table3.html How can i make the rule i have no experience on that
|
phranque

msg:4555223 | 11:26 am on Mar 15, 2013 (gmt 0) |
with all due respect, from the Apache Web Server forum charter: It is not appropriate to expect other members to write your code for you or to debug your entire project; Please don't expect other members to solve a problem you don't want to begin solving yourself. http://www.webmasterworld.com/apache/charter.htm [webmasterworld.com] between lucy24's post and mine you have everything you need to give it a shot on your own. try some code and post your results. if you need more help, post the code you tried as well.
|
buildersweb

msg:4555225 | 11:37 am on Mar 15, 2013 (gmt 0) |
I will try it. I saw your post but i wanted to make it more clear because last post gave me the impression that i have not said it that clear. Is there any basics to read in order to understand better start anchor end anchor ect.. ? thanks
|
phranque

msg:4555248 | 12:36 pm on Mar 15, 2013 (gmt 0) |
apache's mod_rewrite uses perl compatible regular expressions. for your purposes here you should read these three sections. Simple word matching: http://perldoc.perl.org/perlretut.html#Grouping-things-and-hierarchical-matching Grouping things: http://perldoc.perl.org/perlretut.html#Grouping-things-and-hierarchical-matching Extracting matches: http://perldoc.perl.org/perlretut.html#Extracting-matches
|
lucy24

msg:4555470 | 10:35 pm on Mar 15, 2013 (gmt 0) |
Some aspects of anchoring are Apache-specific, so RegEx docs can't explain anything beyond the basic concept of ^ and $ Given www.example.com/directory/filename.php?query=abc to make a RewriteRule aimed at this page, mod_rewrite would say ^/directory/filename\.php$ in the config file, or ^directory/filename\.php$ in htaccess There are further quirks to both ^ and $ but you don't need to know them. Yet ;)
|
buildersweb

msg:4557555 | 8:02 pm on Mar 22, 2013 (gmt 0) |
Thank you all for your advices. The rule works for me was: RewriteRule ^en/(.*)$ http://www.example.com/$1 [R=301,L] I read the tutorial for perl compatible regular expressions. Can you suggest me a basic tutorial for .htaccess, mod_rewrite or apache web server?
|
phranque

msg:4557573 | 9:20 pm on Mar 22, 2013 (gmt 0) |
that rule looks suitable. you didn't say which version of apache you have installed so the links below refer to the current version (2.4) and if you are on an older version be sure to refer to the corresponding version of the docs. Apache HTTP Server Tutorial: .htaccess files: http://httpd.apache.org/docs/current/howto/htaccess.html [httpd.apache.org] Apache mod_rewrite Introduction - Apache HTTP Server: http://httpd.apache.org/docs/current/rewrite/intro.html [httpd.apache.org] Apache HTTP Server Version 2.4 Documentation - Apache HTTP Server: http://httpd.apache.org/docs/2.4/ [httpd.apache.org]
|
g1smd

msg:4557596 | 10:35 pm on Mar 22, 2013 (gmt 0) |
This looks OK.
RewriteRule ^en/(.*)$ http://www.example.com/$1 [R=301,L] I would make two minor changes.
RewriteRule ^en/(.*) http://www.example.com/$1 [R=301,NC,L] Since .* is greedy, the $ isn't needed. I'd probably also redirect stray requests for /En/, /eN/ and /EN/ using the [NC] flag.
|
|