homepage Welcome to WebmasterWorld Guest from 54.196.62.23
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Help redirect old presta links
presta 1.3, redirects, old links
buildersweb



 
Msg#: 4553549 posted 6:14 pm on Mar 11, 2013 (gmt 0)

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 ?

 

phranque

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



 
Msg#: 4553549 posted 12:55 am on Mar 12, 2013 (gmt 0)

^thepid=1777$

your regex has a start and end anchor which will fail the conditional test of QUERY_STRING.

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4553549 posted 2:06 am on Mar 12, 2013 (gmt 0)

You'll need (^|&) and (&|$) here.

buildersweb



 
Msg#: 4553549 posted 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

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4553549 posted 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#: 4553549 posted 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#: 4553549 posted 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

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



 
Msg#: 4553549 posted 10:30 am on Mar 12, 2013 (gmt 0)

you'll need those grouping parentheses as provided in g1smd's example.

phranque

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



 
Msg#: 4553549 posted 10:32 am on Mar 12, 2013 (gmt 0)

what response do you get?

buildersweb



 
Msg#: 4553549 posted 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

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



 
Msg#: 4553549 posted 10:55 am on Mar 12, 2013 (gmt 0)


RewriteEngine on


do you have any other working mod_rewrite directives in that .htaccess file?

buildersweb



 
Msg#: 4553549 posted 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

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4553549 posted 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#: 4553549 posted 11:56 am on Mar 12, 2013 (gmt 0)

I moved it to the start of htaccess.
That worked

THANKS!

buildersweb



 
Msg#: 4553549 posted 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

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



 
Msg#: 4553549 posted 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#: 4553549 posted 10:38 am on Mar 15, 2013 (gmt 0)

no everything is /en/ that need to be redirected to /
actually to be deleted

phranque

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



 
Msg#: 4553549 posted 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

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



 
Msg#: 4553549 posted 10:58 am on Mar 15, 2013 (gmt 0)

actually to be deleted

deleted or moved to the root?

lucy24

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



 
Msg#: 4553549 posted 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#: 4553549 posted 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

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



 
Msg#: 4553549 posted 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#: 4553549 posted 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

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



 
Msg#: 4553549 posted 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

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



 
Msg#: 4553549 posted 10:35 pm on Mar 15, 2013 (gmt 0)

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 ;)

buildersweb



 
Msg#: 4553549 posted 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

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



 
Msg#: 4553549 posted 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

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4553549 posted 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved