Вопрос

I'm trying to route all unexisting folders to a specific PHP script with mod_rewrite but I couldn't handle it.

Here is the scenario, I've some folders like /images, /gallery, /js etc. Some of them has their own .htaccess files and php scripts under directories...

What I have to do is, without blocking these folders and their own rules redirecting all other requests to /subject/content.php file..

I tried something like this but unfortunately doesn't work

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9]+)/(.*)-(.*).html /subject/content.php?ID=$2

At the end, URLs should be like /sports/123-how-to-lose-weight.html

Also I'm trying the same for category pages. And they should be routed like www.blabla.com/sports --> /subject/category.php?cat=sports

(ps: I also couldn't see anything on RewriteLog with level 9 logging when requesting pages according to upper rules)

Thank you very much for your help :)

Это было полезно?

Решение

Could you try these;

// stop greedy search by "?" while using .*
RewriteRule ^([a-zA-Z0-9]+)/(.*?)-(.*?)\.html /subject/content.php?ID=$2
// or more better regexp, afak \w & \d will wolk too
RewriteRule ^([\w\d-]+)/(\d+)-([\w\d-]+)\.html /subject/content.php?ID=$2
// if not set as RewriteBase /
RewriteRule ^([\w\d-]+)/(\d+)-([\w\d-]+)\.html subject/content.php?ID=$2

But first: RewriteEngine On. :)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top