Exception on redirect and sefurls

Discuss practical ways rearrange URLs using mod_rewrite.

Exception on redirect and sefurls

Postby shortye » Wed Jul 09, 2008 2:21 pm

Hi there.
Usually i'm ok with htaccess, as long if it is not to difficult, but this one i can't seem to get done.

I have my old sef url's and i need to redirect them to my new sef urls, except of course the new sefurls that just need to be re-written.

Example:
my old sef urls are: assignment/client/projectname.html
and i want to change these in to: blog/assignment/client/projectname/
but, these should also work assignment/client/projectname or assignment/client/projectname.html and all should be redirected permantly to the new one. Then the new one's should be rewritten, see code below


Code: Select all
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule \.(jpe?g|bmp|png|gif|JPE?G)$ cms/images/404image.png [L]
RewriteRule \.(css|jpe?g|gif|png|js|htc)$ - [L]

RewriteRule ^portfolio/(.*)$ index/$1 [N]

RewriteCond %{REQUEST_URI} !^(portfolio/|blog/|index/|contact/)(.*)$
RewriteRule ^(.*)$ blog/$1 [R=301]

RewriteRule ^(.*)/(.*)/(.*)/(.*)/$ $1.php?menu=$2&page=$3&id=$4 [L]
RewriteRule ^(.*)/(.*)/(.*)/(.*).html$ $1.php?menu=$2&page=$3&id=$4 [L]

RewriteRule ^(.*)/(.*)/(.*)/$ $1.php?menu=$2&page=$3 [L]
RewriteRule ^(.*)/(.*)/(.*).html$ $1.php?menu=$2&page=$3 [L]

RewriteRule ^(.*)/(.*)/$ $1.php?menu=$2 [L]
RewriteRule ^(.*)/(.*).html$ $1.php?menu=$2 [L]

RewriteRule ^(.*)/$ $1.php [L]
RewriteRule ^(.*).html$ $1.php [L]



I hope i can get across my problem.
If anybody has an idea? thanks a million!
shortye
 
Posts: 3
Joined: Wed Jul 09, 2008 1:40 pm

Postby richardk » Wed Jul 09, 2008 2:31 pm

Is it supposed to work for /assignment and /assignment/client too?

Example:
my old sef urls are: assignment/client/projectname.html
and i want to change these in to: blog/assignment/client/projectname/
but, these should also work assignment/client/projectname or assignment/client/projectname.html and all should be redirected permantly to the new one. Then the new one's should be rewritten, see code below

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^blog/([^/]+)/([^/]+)/([^/]+)/?$ /do-something [QSA,L]

RewriteRule ^([^/]+/[^/]+/[^/]+)(\.html|/)?$ /blog/$1/ [R=301,L]

But i can't fit it into what you've already got without you explaining more about it.

Edit: You can try this as well
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule \.(jpe?g|bmp|png|gif)$ /cms/images/404image.png [NC,L]

RewriteRule \.(css|jpe?g|gif|png|js|htc)$ - [NC,L]

RewriteRule ^portfolio/(.*)$ index/$1

RewriteCond %{REQUEST_URI} !^(portfolio/|blog/|index/|contact/)(.*)$
RewriteRule ^((.+)(\.html|/)|(.+))?$ /blog/$2$4 [R=301,L]

RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ /$1.php?menu=$2&page=$3&id=$4 [QSA,L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$         /$1.php?menu=$2&page=$3       [QSA,L]
RewriteRule ^([^/]+)/([^/]+)/$                 /$1.php?menu=$2               [QSA,L]
RewriteRule ^([^/]+)/$                         /$1.php                       [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby shortye » Wed Jul 09, 2008 2:52 pm

Is it supposed to work for /assignment and /assignment/client too?


yes if it is possible

so all my old links should be redirected from
Code: Select all
assignment/client/projectname
to
Code: Select all
blog/assignment/client/projectname

with or without trailing slash or .html

but if the url starts with one of the following:
Code: Select all
portfolio
contact
index

with or without trailing slash or .html or slash anything that goes.
They should no be redirected to blog/

if that is all done I need to rewrite all the url's to php processable format's.

In the following example, blog can thus also be portfolio,contact or index.

Code: Select all
blog or
blog/ or
blog.html or
=> blog.php


Code: Select all
blog/assignment
blog/assignment/
blog/assigment.html
=>blog.php?menu=assignment


Code: Select all
blog/assignment/client
blog/assignment/client/
blog/assignment/client.html
=>blog.php?menu=assignment&page=client

Code: Select all
blog/assignment/client/projectname
blog/assignment/client/projectname/
blog/assignment/client/projectname.html
=>blog.php?menu=assignment&page=client&id=projectname
shortye
 
Posts: 3
Joined: Wed Jul 09, 2008 1:40 pm

Postby shortye » Wed Jul 09, 2008 3:20 pm

Hi, tried your code, i forgot to mention there is a RewriteBase. Always problematic but i changed the code to the following:

add the base to the redirect en cond
delete the slashes in the cond
add the slash at blog/$2$4/
and that did the trick.



Code: Select all
Options +FollowSymLinks
RewriteEngine On
RewriteBase /cmd/newportfolio/

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule \.(jpe?g|bmp|png|gif)$ /cms/images/404image.png [NC,L]

RewriteRule \.(css|jpe?g|gif|png|js|htc)$ - [NC,L]

RewriteRule ^portfolio/(.*)$ index/$1

RewriteCond %{REQUEST_URI} !^/cmd/newportfolio/(portfolio|blog|index|contact)(.*)$
RewriteRule ^((.+)(\.html|/)|(.+))?$ /cmd/newportfolio/blog/$2$4/ [R=301,L]

RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ $1.php?menu=$2&page=$3&id=$4 [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$         $1.php?menu=$2&page=$3       [L]
RewriteRule ^([^/]+)/([^/]+)/$                 $1.php?menu=$2               [L]
RewriteRule ^([^/]+)/$                         $1.php                       [L]


This seems to do the trick, i'll do some more test before i will confirm.
Thanks a million! Again a good learning experience. Have your website in my favorites since long. Perfect resource.
shortye
 
Posts: 3
Joined: Wed Jul 09, 2008 1:40 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 84 guests

cron