English 中文(简体)
How to get LiteSpeed to evaluate all rewrite rules in .htaccess as apache2 does?
原标题:

I have problems with LiteSpeed not evaluating mod_rewrite rules the same way as apache2

I have a php routing system with a mod_rewrite setting that rewrites http://example.com/page-name to http://example.com/index.php/page-name with $_SERVER[ REQUEST_URI ]. This works fine.

I have now added a URI to generate thumbnails from an image URI called ex http://example.com/generate-thumbnail?uri=/images/thumbnails/1.jpg. This URL generates a thumbnail image that is saved to http://example.com/images/thumbnail/1.jpg to enable caching.

The next step is a regexp that checks if an image at http://example.com/images/thumbnail/1.jpg and if not runs http://example.com/generate-thumbnail?uri=/images/thumbnails/1.jpg to generate a new thumbnail.

The .htaccess file below works great in apache2 but does not work at my hosting service that runs LiteSpeed. On LiteSpeed only the first rewrite rules is evaluated so that if http://example.com/generate-thumbnail?uri=/images/thumbnails/1.jpg does not exist the server seem to look for the file http://example.com/generate-thumbnail instead of evaluating the last rewrite rules that would result in the correct URL http://example.com/index.php/generate-thumbnail?uri=/images/thumbnails/1.jpg.

apache2 get this right but not LiteSpeed, why?

If I change the RewriteRule (.*) /generate-thumbnail?uri=$1 [L] to RewriteRule (.*) /file_that_exists.php?uri=$1 [L] where file_that_exists.php is a real file, everything works fine in LiteSpeed.

How can I get LiteSpeed to evaluate all the rewrite rules?

# Start the rewrite engine
RewriteEngine On

# Rewrite if post image was requested but is not cached, generate it
RewriteCond %{REQUEST_URI} ^/images/thumbnails/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) /generate-thumbnail?uri=$1 [L]

# Rewrite the page into the router
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
问题回答

mod_rewrite too should stop at the /generate-thumbnail rule due to the [LAST] flag. Remove that [L] if you actually want the index.php/ rule to apply as well.

Since LiteSpeed claims compatibility with Apache, I would surmise it s a commercial fork. If so, I don t understand how it could divert here. But anyway, enable the RewriteLog otherwise to find the cause.





相关问题
URL rewrite in IIS6 - Third party tools

I have collected the following api/sdk/whatever which provide modules for doing url rewriting in IIS 5/6/7. Some are free-open source and some require $. I haven t tried any of them. I would like to ...

Rewrite spring-security redirect URLs

I m trying to get Tuckey UrlRewriteFilter to tidy up URLs for my webapp. One problem I ve got is that when spring-security notices that an anonymous user is trying to access a protected resource it ...

ASP.NET Friendly URLs

In my research, I found 2 ways to do them. Both required modifications to the Application_BeginRequest procedure in the Global.Asax, where you would run your code to do the actual URL mapping (mine ...

Could I get by HttpModule the URL that contains * before?

My web-site is working under ASP.NET 3.5, IIS7, Integrated pipiline mode. My HttpModule is getting request to all resources, including URLs like this: http://my-site.com/address And I would support *...

Domains & Foreward Slash

This is rather difficult to explain so please bear with me. We will be hosting 4 websites on our server and the plan is to have each site sit under its own domain: site-a.com site-b.com sub1.site-b....

URL Mod-Rewrite

I currently have a working URL: http://example.com/security-services.php?service=fixed-camera-surveillance and then I have PHP say, $_REQUEST[ service ] to do some stuff... But I d like to ...

热门标签