narmi2
asked on
URL Rewriting HTACCESS
Dear Experts,
I have the following type of url
http://www.narmi.com/page.php?category=1&surname=smith&forename=smith
How do I re-write that using .htaccess so it looks something like this
http://www.narmi.com/service-type=goes-here/category-type-goes-here/the-team/john-smith.php
For example
http://www.narmi.com/organisation/charity-services/the-team/john-smith.php
category 1 = charity services in the database
category 2 = some other service
category 3 and so on
Is this possible?
I have the following type of url
http://www.narmi.com/page.php?category=1&surname=smith&forename=smith
How do I re-write that using .htaccess so it looks something like this
http://www.narmi.com/service-type=goes-here/category-type-goes-here/the-team/john-smith.php
For example
http://www.narmi.com/organisation/charity-services/the-team/john-smith.php
category 1 = charity services in the database
category 2 = some other service
category 3 and so on
Is this possible?
ASKER
Hello,
Could you please explain what's happening in the script?
Could you please explain what's happening in the script?
ASKER
That script does not work. It makes all my existing re-written urls go to the home page index.php.
this should work, haven't tested it, but its defenatly the right direction.
RewriteRule ^/page.php?category=([^&]+ )[^=]=([^& ]+)[^=]=([ ^&]+)$ /$1/$2/$3
RewriteRule ^/page.php?category=([^&]+
ASKER
It doesn't work.
I think I need to change the url to something like this
http://www.narmi.com/organisation/charity-services-1/the-team/john-smith.php
so the category 1 is in the new url after charity-services
How do I do that?
I think I need to change the url to something like this
http://www.narmi.com/organisation/charity-services-1/the-team/john-smith.php
so the category 1 is in the new url after charity-services
How do I do that?
thy this: RewriteRule ^/page.php?category=([^&]+ )[^=]=([^& ]+)[^=]=([ ^&]+)[^=]= ([^&]+)$ /organisation/$2/$1/$4-$3. php
post me the url you tried after and before the redirect so i can see what happend.
post me the url you tried after and before the redirect so i can see what happend.
ASKER
That still doesn't work. I would like to get to
http://www.narmi.com/page.php?category=1&forename=john&surname=smith
by typing in
http://www.narmi.com/organisation/charity-law-1/the-team/john-smith.php
http://www.narmi.com/page.php?category=1&forename=john&surname=smith
by typing in
http://www.narmi.com/organisation/charity-law-1/the-team/john-smith.php
I have been doing it back to front :-( its easier this way round
RewriteRule ^organisation/[^0-9]([0-9] )/the-team /([a-z])-( [a-z]).php page.php?category=$1&foren ame=$2&sur name=$3
RewriteRule ^organisation/[^0-9]([0-9]
ASKER
Still doesn't work. I have also tried this:
RewriteRule ^organisation/[a-z-]+-([0- 9]+)/the-t eam/([a-z] +)-([a-z]+ ).php page.php?category=$1&foren ame=$2&sur name=$3
RewriteRule ^organisation/[a-z-]+-([0-
whats the result, i cant find the mistake if i dont know the result?
ASKER
It seems to give me the sitemap for my site without any css. So it's almost like it is trying to find the physical path organisation/charity-law-1 /the-team/
which is not what it should be doing.
I have another rule in the .htaccess file which redirects to the sitemap if the url typed is not found i.e.
ErrorDocument 404 /sitemap.php
which is not what it should be doing.
I have another rule in the .htaccess file which redirects to the sitemap if the url typed is not found i.e.
ErrorDocument 404 /sitemap.php
ASKER
I did the following as a test:
RewriteRule ^organisation/charity-law- 1/the-team /john-smit h.php page.php?category=1&forena me=john&su rname=smit h [L]
and typed in the following url into the browser
http://www.narmi.com/organisation/charity-law-1/the-team/john-smith.php
and it gave me the correct page but with no formatting, i.e. no css...
RewriteRule ^organisation/charity-law-
and typed in the following url into the browser
http://www.narmi.com/organisation/charity-law-1/the-team/john-smith.php
and it gave me the correct page but with no formatting, i.e. no css...
you have to exclude the .css files from the rule before your rule
RewriteCond %{REQUEST_FILENAME} !^*.css
RewriteRule ^organisation/[a-z-]*([0-9 ]+)/the-te am/([a-z]+ )-([a-z]+) .php page.php?category=$1&foren ame=$2&sur name=$3
RewriteCond %{REQUEST_FILENAME} !^*.css
RewriteRule ^organisation/[a-z-]*([0-9
ASKER
My css files are in the root along with page.php i.e.
www.narmi.com/page.php
www.narmi.com/style.css
So with this in mind, is the following correct?
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|/[^. ]*)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^*.css
RewriteRule ^organisation/[a-z-]+-([0- 9]+)/the-t eam/([a-z] +)-([a-z]+ ).php page.php?category=$1&foren ame=$2&sur name=$3
www.narmi.com/page.php
www.narmi.com/style.css
So with this in mind, is the following correct?
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|/[^.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^*.css
RewriteRule ^organisation/[a-z-]+-([0-
ASKER
I asked the above, because it gives me an internal server error message when I try to access any part of my site...
i think you dont need my conition because of your first one.
sorry it should have been: RewriteCond %{REQUEST_FILENAME} !^.*\.css
sorry it should have been: RewriteCond %{REQUEST_FILENAME} !^.*\.css
a very small mistake i pointed out before: RewriteRule ^organisation/[a-z-]+([0-9 ]+)/the-te am/([a-z]+ )-([a-z]+) .php page.php?category=$1&foren ame=$2&sur name=$3
NOT: [a-z-]+-([0-9]+)
NOT: [a-z-]+-([0-9]+)
ASKER
I have made those changes which is now giving better results but still missing the css formatting on the page.
I have tried:
RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|/[^. ]*)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^.*\.css
RewriteRule ^organisation/[a-z-]+([0-9 ]+)/the-te am/([a-z]+ )-([a-z]+) .php page.php?category=$1&foren ame=$2&sur name=$3 [L]
and this:
RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|/[^. ]*)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^organisation/[a-z-]+([0-9 ]+)/the-te am/([a-z]+ )-([a-z]+) .php pagey.php?category=$1&fore name=$2&su rname=$3 [L]
both do the same thing, i.e. correct page but no css formatting?
Typed URL = http://www.narmi.com/organisation/charity-law-123/the-team/john-smith.php
I have tried:
RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|/[^.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^.*\.css
RewriteRule ^organisation/[a-z-]+([0-9
and this:
RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|/[^.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^organisation/[a-z-]+([0-9
both do the same thing, i.e. correct page but no css formatting?
Typed URL = http://www.narmi.com/organisation/charity-law-123/the-team/john-smith.php
RewriteCond %{REQUEST_URI} (\.htm|\.php|\.html)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^organisation/[a-z-]+([0-9 ]+)/the-te am/([a-z]+ )-([a-z]+) \.php pagey.php?category=$1&fore name=$2&su rname=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^organisation/[a-z-]+([0-9
ASKER
Changed to (showing full script)
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} (\.htm|\.php|\.html)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^organisation/[a-z-]+([0-9 ]+)/the-te am/([a-z]+ )-([a-z]+) .php page.php?category=$1&foren ame=$2&sur name=$3 [L]
But still giving same error as before, i.e. correct page but no css formatting.
css formatting works when I type
www.narmi.com/page.php?category=123&forename=john&surname=smith
but does not work if I do
http://www.narmi.com/organisation/charity-law-123/the-team/john-smith.php
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} (\.htm|\.php|\.html)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^organisation/[a-z-]+([0-9
But still giving same error as before, i.e. correct page but no css formatting.
css formatting works when I type
www.narmi.com/page.php?category=123&forename=john&surname=smith
but does not work if I do
http://www.narmi.com/organisation/charity-law-123/the-team/john-smith.php
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you could also define aliases for images and css.
ASKER
Ok, by adding a / before all images and css files in the html seems to have fixed the problem. However, all links on that page no longer work.
For example, if I click home page, instead of going to http://www.narmi.com/index.php, goes to http://www.narmi.com/organisation/charity-law-1/index.php
How do I stop that from happening?
For example, if I click home page, instead of going to http://www.narmi.com/index.php, goes to http://www.narmi.com/organisation/charity-law-1/index.php
How do I stop that from happening?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this :
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|/[^.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.php
Regards