Welcome to WebmasterWorld Guest from 54.161.201.189

Forum Moderators: Ocean10000 & incrediBILL & phranque

Help redirect old presta links

presta 1.3, redirects, old links

   
6:14 pm on Mar 11, 2013 (gmt 0)

5+ Year Member



Hello

I try to redirect old presta non sef links to new sef links

The old url is :

www.mydomain.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

The new url is
[mydomain.com...]

So i tried that but with no luck


RewriteCond %{QUERY_STRING} ^thepid=1777$
RewriteRule ^details2\.php$ http://www.mydomain.com/en/corner-sofas/302-sofa-corn.html? [R=301,L]


What i have done wrong ? Can you help me please ?
12:55 am on Mar 12, 2013 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



^thepid=1777$

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

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



You'll need (^|&) and (&|$) here.
9:33 am on Mar 12, 2013 (gmt 0)

5+ Year Member



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
9:46 am on Mar 12, 2013 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Where did the brackets go?

Use example.com in this forum so that the code is readable.
10:00 am on Mar 12, 2013 (gmt 0)

5+ Year Member



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 ?
10:30 am on Mar 12, 2013 (gmt 0)

5+ Year Member



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]

10:30 am on Mar 12, 2013 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



what response do you get?
10:41 am on Mar 12, 2013 (gmt 0)

5+ Year Member



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
10:55 am on Mar 12, 2013 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month




RewriteEngine on


do you have any other working mod_rewrite directives in that .htaccess file?
11:33 am on Mar 12, 2013 (gmt 0)

5+ Year Member



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]

11:39 am on Mar 12, 2013 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Redirects should be listed before rewrites.

Literal periods in RegEx patterns should be escaped.
11:56 am on Mar 12, 2013 (gmt 0)

5+ Year Member



I moved it to the start of htaccess.
That worked

THANKS!
9:59 am on Mar 15, 2013 (gmt 0)

5+ Year Member



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 ?
10:09 am on Mar 15, 2013 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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

5+ Year Member



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

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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.)
10:58 am on Mar 15, 2013 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



actually to be deleted

deleted or moved to the root?
11:05 am on Mar 15, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



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]
11:20 am on Mar 15, 2013 (gmt 0)

5+ Year Member



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
11:26 am on Mar 15, 2013 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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.
11:37 am on Mar 15, 2013 (gmt 0)

5+ Year Member



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
12:36 pm on Mar 15, 2013 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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
10:35 pm on Mar 15, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



start anchor end anchor

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 ;)
8:02 pm on Mar 22, 2013 (gmt 0)

5+ Year Member



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?
9:20 pm on Mar 22, 2013 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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]
10:35 pm on Mar 22, 2013 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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.
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month