Hi,

Please help me work out this mod-rewrite issue while trying to make my urls SEF.

RewriteEngine On
Options +FollowSymLinks

# Browse Category
RewriteRule ^category/[!/.]*([A-Za-z]+)/?$ /browse.php?cat=$1    [NC,L]

# View Item
RewriteRule ^view/([0-9]+)/([a-zA-Z0-9-]+)$ /view.php?item_id=$1&sef=$2 [NC]

This is my current .htacess.

The browse category rule is working ok
converting - http://localhost/browse.php?cat=people
into - http://localhost/category/people

the view item is giving a 404
trying to convert - http://localhost/view.php?item_id=28&sef=2009-bristol-blenheim-in-west-yorkshire
into - http://localhost/view/28/2009-bristol-blenheim-in-west-yorkshire

Strange. I can confirm that the rules work correctly for me, which would suggest it's a server config issue, rather than a problem with the rules themselves.

I had to disable MultiViews to get the rewrite to pass the parameters through, but even without that, it wasn't returning a 404.

You don't happen to have a symbolic link related to view at all do you?

added Options -Multiviews and is now working :)

thank you very much

another quick rewrite question..

can i add another Rewrite rule which will turn my basic /home.php, /sign-up.php into just /home , /sign-up (dropping the .php)

which will not interfere with my current rules?

Funnily enough, if you had MultiViews enabled, that would have already worked, although it'd be exploiting the functionality in a way it's perhaps not meant to be used.

MultiViews looks for a file / directory that is similar to the URL requested if a specific match isn't found.

Alternatively, you could try:

RewriteRule ^(.*)/$ /$1.php

makes sense but i tried it as follows

`

RewriteEngine On
Options +FollowSymLinks
Options -Multiviews

RewriteRule ^(.*)/$ /$1.php

# Browse Category
RewriteRule ^category/[!/.]*([A-Za-z]+)/?$ /browse.php?cat=$1    [NC,L]

# View Item
RewriteRule ^view/([0-9]+)/([a-zA-Z0-9-]+)$ /view.php?item_id=$1&sef=$2 [NC]

getting

Not Found

The requested URL /home was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

`

Remove the trailing slash in the RewriteRule and probably best to add a check that the request isn't for a physical file or directory:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /$1.php

And you may find the rule needs to be the last RewriteRule to prevent conflict with the two aforementioned.

thought so, but i tried that and i get ISE

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Did you try the changes before I updated my last post?

Post what your .htaccess file looks like now...

just tried your edit, works now. thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.