Change path

Discuss practical ways rearrange URLs using mod_rewrite.

Change path

Postby Pablo90 » Wed Nov 12, 2008 9:29 am

Hi guys, I've a problem.

My slag is tfn.com/directory/xxx/

where xxx can be "news/news-title" or "dvds" etc..

My problem is that I've to change "directory" (not just in that path but in different one) and I would like that if I guest go to tfn.com/directory/xxx/
the server or whatever it is redirect him to tfn.com/new_dir/xxx/ . It doesn't have to change whatever "xxx" it is..

I would like to know what code I need to insert in my .htaccess, and if possibile I would like to say what are the directory in a text file.

I mean that I create a file .txt and I insert sth like:

directory <--> new_dir

and it knows that it have to change "directory" with "new_dir".

Can you help me guys?Thank you in advance, Paolo
Pablo90
 
Posts: 18
Joined: Thu Oct 09, 2008 7:45 am

Postby richardk » Wed Nov 12, 2008 12:43 pm

A redirect that the user sees?
Code: Select all
Redirect 301 /old_dir http://www.example.com/new_dir


Or that the user can't see
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^dir_from_address_bar(/(.*))?$ /dir_with_the_files/$2 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Pablo90 » Thu Nov 13, 2008 8:54 am

sorry can you edit the second code with the old directory named "cartella_vecchia" and the new one "cartella_nuova" so I can understand what I've exactly to change :D
Pablo90
 
Posts: 18
Joined: Thu Oct 09, 2008 7:45 am

Postby richardk » Fri Nov 14, 2008 1:05 pm

the old directory named "cartella_vecchia" and the new one "cartella_nuova"

Which one are you visiting?
Which one contains the working files?
Should the browser address bar change?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Pablo90 » Sun Nov 16, 2008 10:14 am

richardk wrote:
the old directory named "cartella_vecchia" and the new one "cartella_nuova"

Which one are you visiting?
Which one contains the working files?
Should the browser address bar change?


the directory that doesn't work is "cartella_vecchia" and the working one is "cartella_nuova".
I just know that google want the "301 redirect" to refresh the urls..
Pablo90
 
Posts: 18
Joined: Thu Oct 09, 2008 7:45 am

Postby richardk » Sun Nov 16, 2008 11:17 am

If you want a 301 redirect,
Code: Select all
Redirect 301 /cartella_vecchia http://www.example.com/cartella_nuova
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Pablo90 » Sun Nov 16, 2008 11:22 am

richardk wrote:If you want a 301 redirect,
Code: Select all
Redirect 301 /cartella_vecchia http://www.example.com/cartella_nuova

yes, but I have to put it into the htaccess?
And if go to /cartella_vecchia/filexxx.html it redirect me to /cartella_nuova/index.html or /cartella_nuova/filexxx.html ?
Pablo90
 
Posts: 18
Joined: Thu Oct 09, 2008 7:45 am

Postby richardk » Sun Nov 16, 2008 11:23 am

Yes.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Pablo90 » Mon Nov 24, 2008 11:27 am

Hi, I tried the code and it works for what I asked for, but there's a problem.


Code: Select all
AddDefaultCharset iso-8859-1

# BEGIN Gruppo Modulo Rewrite

<IfModule mod_rewrite.c>
RewriteEngine on

# Change following path

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)$ $1/ [L]
RewriteRule ^([A-Za-z0-9-]+)/$ index.php?act=$1&tid=$1 [L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)/pagina-([0-9]+)$ $1/pagina-$2/ [L]
RewriteRule ^([A-Za-z0-9-]+)/pagina-([0-9]+)/$ index.php?act=$1&tid=$1&page=$2 [L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ $1/$2/ [L]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/$ index.php?act=telefilm&tid=$1&mod=$2 [L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/stagione-([0-9]+)$ $1/$2/stagione-$3/ [L]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/stagione-([0-9]+)/$ index.php?act=telefilm&tid=$1&mod=$2&season=$3 [L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ $1/$2/$3/ [L]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/$ index.php?act=show&slug=$3 [L]

</IfModule>

# END Gruppo Modulo Rewrite

# Qui redirect per telefilm e notizie
Redirect 301 /greeek http://www.***.com/greek/

# Error Pages

ErrorDocument 401 /?act=error&e=401
ErrorDocument 403 /?act=error&e=403
ErrorDocument 404 /?act=error&e=404
ErrorDocument 500 /?act=error&e=500

RewriteEngine on

# -FrontPage-

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>

<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName telefilmsnetwork.com
AuthUserFile /home/telefilm/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/telefilm/public_html/_vti_pvt/service.grp



As you can see:

# Qui redirect per telefilm e notizie
Redirect 301 /greeek http://www.***.com/greek/

that's your code, and this is what happens:

I go towww.***.com/greeek/news/
and it redirect me to the right page, but the url is this:
http://www.***.com/greek//news/?act=tel ... k&mod=news

How can I solve this problem? Thanks in advance, Paolo
Pablo90
 
Posts: 18
Joined: Thu Oct 09, 2008 7:45 am

Postby richardk » Mon Nov 24, 2008 1:18 pm

The problem is the mod_rewrite is running before the Redirect.

Try
Code: Select all
AddDefaultCharset iso-8859-1
Options +FollowSymLinks

# Error Pages
ErrorDocument 401 /?act=error&e=401
ErrorDocument 403 /?act=error&e=403
ErrorDocument 404 /?act=error&e=404
ErrorDocument 500 /?act=error&e=500


<IfModule mod_rewrite.c>
  RewriteEngine On

  # Qui redirect per telefilm e notizie
  RewriteRule ^greeek(/(.*))?$ /greek/$2 [R=301,L]

  # BEGIN Gruppo Modulo Rewrite
  RewriteCond %{SCRIPT_FILENAME} !-f
  RewriteCond %{SCRIPT_FILENAME} !-d
  RewriteRule ^[-a-z0-9]+(?:/[-a-z0-9]+(?:/[-a-z0-9]+)?)?$ /$1/ [R=301,L]

  RewriteRule ^([-a-z0-9]+)/$                                index.php?act=$1&tid=$1                        [NC,L]
  RewriteRule ^([-a-z0-9]+)/pagina-([0-9]+)/$                index.php?act=$1&tid=$1&page=$2                [NC,L]
  RewriteRule ^([-a-z0-9]+)/([-a-z0-9]+)/$                   index.php?act=telefilm&tid=$1&mod=$2           [NC,L]
  RewriteRule ^([-a-z0-9]+)/([-a-z0-9]+)/stagione-([0-9]+)/$ index.php?act=telefilm&tid=$1&mod=$2&season=$3 [NC,L]
  RewriteRule ^([-a-z0-9]+)/([-a-z0-9]+)/([-a-z0-9]+)/$      index.php?act=show&slug=$3                     [NC,L]
  # END Gruppo Modulo Rewrite
</IfModule>

# -FrontPage-
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
  Order deny,allow
  Deny from all
  Allow from all
</Limit>

<Limit PUT DELETE>
  Order deny,allow
  Deny from all
</Limit>

AuthName telefilmsnetwork.com
AuthUserFile /home/telefilm/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/telefilm/public_html/_vti_pvt/service.grp
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Next

Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: Google [Bot] and 19 guests

cron