开发者

isapi rewrite help

Hi there I have the following isapi rewrite rule working on IIS 6.

it rewrites:

http://www.mysite.com/index.php?category=white-wine

to:

http://www.mysite.com/white-wine

.htaccess contents:

RewriteEngine on
RewriteBase / 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^/]+)/?$ /?category=$1 [NC,QSA,L]

I am now trying to do almost the same rule but in a folder deeper. edit The rule is in the same .htaccess file in the site root i simply want to apply the above rule, to an index.php file that is in a folder in the root called products.

I want to rewrite:

http://www.mysite.com/product/index.php?product=the-chosen-product 

to:

http://www.mysite.com/product/the-chosen-product

I have tried this:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^/]+)/product/?$ /product/?product=$1 [NC,QSA,L]

This is not working though I get a load of errors on my php page:

Warning: require_once() [function.require-once]: URL file-access is disabled in the server configuration

Warning: require_once(http://www.mysite.com/myfolder/framework/library.php) [function.require-once]: failed to open stream: no suitable wrapper could be found

I was originally getting those errors with the first rule, but as that is working now开发者_如何学C, I guess it must be possible to do the second rule somehow?

Also how would I change it so instead of displaying:

http://www.mysite.com/product/my-chosen-product 

it would show:

http://www.mysite.com/product/my-chosen-product.htm

I am really new to this. I have looked through many other posts and I thoroughly confused, particularly as isapi rewrite, I think, works a little differently to mod_rewrite.


RE: "Warning: require_once() [function.require-once]: URL file-access is disabled...".

Do not use require_once(http://www.mysite.com/myfolder/framework/library.php) -- it is forbidden on your server (but even if it would be enabled -- it is not recommended to do it in this way). Use require_once($_SERVER['DOCUMENT_ROOT'] . '/myfolder/framework/library.php') instead.


RE: Rewrite Rule (for products). Use this instead:

RewriteCond ${REQUEST_URI} !^/product/index\.php
RewriteRule ^product/([^/]+)/?$ /product/index.php?product=$1 [NC,QSA,L]

So your whole .htaccess should look like this:

RewriteEngine on
RewriteBase / 

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /index.php?category=$1 [NC,QSA,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^product/([^/]+)/?$ /product/index.php?product=$1 [NC,QSA,L]

I have made some small changes to your rules: specified index.php straight away, otherwise IIS would had to figure out the correct script name later .. which requires some tiny but still resources to do so.


These rules will work with extensionless URLs (e.g. http://www.mysite.com/product/the-chosen-product). If you want to have .htm extensions in such URLs you have to do:

a) Generate those URLs in your application straight away

b) Modify rewrite rules a bit: replace RewriteRule lines with these:

RewriteRule ^([^/]+)\.htm$ /index.php?category=$1 [NC,QSA,L]
RewriteRule ^product/([^/]+)\.htm$ /product/index.php?product=$1 [NC,QSA,L]

With such changes old extension-less URLs (without .htm) will no longer work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜