Need Url Rewriting Help

Discuss practical ways rearrange URLs using mod_rewrite.

Need Url Rewriting Help

Postby Aldini » Thu Jun 26, 2008 2:07 am

My website has a strange structure
The address is http://www.allebouwbedrijven.com . If you go to this url, there is a 302 redirect to http://www.allebouwbedrijven.com/index.php?=home
I don’t know how to change this

The structure of my homepage is :
http://www.allebouwbedrijven.com/index.php?p=home [Homepage}

http://www.allebouwbedrijven.com/index.php?p=alles&c=1 [Overview Company Page]
Sub page of Overview Company Page
http://www.allebouwbedrijven.com/index. ... ls&id=6102 [Company Details]

http://www.allebouwbedrijven.com/index.php?p=toevoegen [Add Company Profile]
http://www.allebouwbedrijven.com/index.php?p=wijzigen [Change Profile]
http://www.allebouwbedrijven.com/links.php [Links]

I want to rewrite the url’s to be more search engine friendly and a permanent 301.

Can someone help me.

Thanks in advance

Aldini
Aldini
 
Posts: 6
Joined: Thu Jun 26, 2008 1:55 am

Postby richardk » Thu Jun 26, 2008 1:19 pm

What do you want the URLs to be?

The address is http://www.allebouwbedrijven.com . If you go to this url, there is a 302 redirect to http://www.allebouwbedrijven.com/index.php?=home
I don’t know how to change this

That is probably due to the PHP script. You will need to ask the author.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Aldini » Thu Jun 26, 2008 2:25 pm

[quote="richardk"]What do you want the URLs to be?

I have rewritten some of the pages :
This page http://www.allebouwbedrijven.com/index.php?p=home [Homepage}
RewriteRule (.*)\.html$ /index.php?p=$1
is now also accesible at http://www.allebouwbedrijven.com/home.html

This page http://www.allebouwbedrijven.com/index.php?p=alles&c=1 [Overview Company Page]
RewriteRule overzicht(.*)-(.*)\.html$ /index.php?p=$1&c=$2
is now also accesible at http://www.allebouwbedrijven.com/overzichtalles-.html

This http://www.allebouwbedrijven.com/index. ... ls&id=6102 [Company Details]
RewriteRule bedrijfsprofiel(.*)-(.*)\.html$ /index.php?p=$1&id=$2
is now also accesible at http://www.allebouwbedrijven.com/bedrij ... -6102.html

But i want to place a 301 redirect so the page will only be available at the new locations.
Aldini
 
Posts: 6
Joined: Thu Jun 26, 2008 1:55 am

Postby richardk » Sat Jun 28, 2008 4:20 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
# Match p=
RewriteCond %{QUERY_STRING} ^(.*&)?p=([^&]+)(&.*)?$ [NC]
# Match c=
RewriteCond %2&%{QUERY_STRING} ^([^&]+)&(.*&)?c=([0-9]+)(&.*)?$ [NC]
#Match the /index.php. Redirect.
RewriteRule ^index\.php$ /overzicht%1-%3.html? [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
# Match p=
RewriteCond %{QUERY_STRING} ^(.*&)?p=([^&]+)(&.*)?$ [NC]
# Match id=
RewriteCond %2&%{QUERY_STRING} ^([^&]+)&(.*&)?id=([0-9]+)(&.*)?$ [NC]
#Match the /index.php. Redirect.
RewriteRule ^index\.php$ /bedrijfsprofiel%1-%3.html? [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
# Match p=
RewriteCond %{QUERY_STRING} ^(.*&)?p=([^&]+)(&.*)?$ [NC]
#Match the /index.php. Redirect.
RewriteRule ^index\.php$ /%2.html? [R=301,L]

RewriteRule ^overzicht([^/]+)-([0-9]+)\.html$       /index.php?p=$1&c=$2  [QSA,L]
RewriteRule ^bedrijfsprofiel([^/]+)-([0-9]+)\.html$ /index.php?p=$1&id=$2 [QSA,L]
RewriteRule ^([^/]+)\.html$                         /index.php?p=$1       [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Aldini » Sat Jun 28, 2008 11:28 pm

thank you very much. is it also possible to have the company name in the url
in stead of bedrijfsprofiel at this section. every bedrijfsprofiel is actually a profile of a company. it would be great if the name of the company would be in the url
RewriteCond %{ENV:REDIRECT_STATUS} ^$
# Match p=
RewriteCond %{QUERY_STRING} ^(.*&)?p=([^&]+)(&.*)?$ [NC]
# Match id=
RewriteCond %2&%{QUERY_STRING} ^([^&]+)&(.*&)?id=([0-9]+)(&.*)?$ [NC]
#Match the /index.php. Redirect.
RewriteRule ^index\.php$ /bedrijfsprofiel%1-%3.html? [R=301,L]
Aldini
 
Posts: 6
Joined: Thu Jun 26, 2008 1:55 am

Postby richardk » Mon Jun 30, 2008 12:38 pm

If you do that, mod_rewrite will not be able to do the redirect as it does not know the company name (unless you have access to the httpd.conf file and can define a RewriteMap). You will also need to change the URL to /companyname-p-id.html or it won't know where the company name ends and the p value begins.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 94 guests

cron