开发者

Nginx Rewrite Catch All Possible ID's

开发者 https://www.devze.com 2023-01-23 04:16 出处:网络
Hey guys, I run a large website where the URL structure for the content pages is: site.com/T8siBD Now the file that is currently catching all the possible ID pages is index.php.

Hey guys, I run a large website where the URL structure for the content pages is: site.com/T8siBD

Now the file that is currently catching all the possible ID pages is index.php.

I run nginx, and I have my 404 error page setup as index.php.

So anything will forward to index.php (if its not there)

And with

$ex               = explode('/', $_SERVER["REQUEST_URI"]); 
$item_key     = isset($ex[1]) ? addslashes(htmlspecialchars($ex[1])) : ''

I can nicely fetch out the ID's.

This works fine in the browser, but if you want to wget any of my content pages, it will give you a 404 error, because in the end, Nginx thinks the 'file' does not exist.

I would like to get round this 404 error page stuff.

I was thinking of using something like:

rewrite ^/(.*)? /index.php?q=$1 last;

But when I do that, it doesn't show any of the 'existing' files on my drive, and basically forwards even images开发者_如何转开发 etc to index.php.

Does anybody know a good way to rewrite this rule?


This will be good if you post full you NGINX config there...

You can try this:

if( !-f $request_filename ){
    rewrite ^/(.*)? /index.php?q=$1 last;
}

Or, better way:

try_files $uri /index.php?q=$uri
0

精彩评论

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